Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007867OCamltoplevelpublic2018-10-26 09:532018-10-27 17:32
Reporterggole 
Assigned Togasche 
PrioritynormalSeveritycrashReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.06.1 
Target VersionFixed in Version4.08.0+dev 
Summary0007867: #mod_use crashes with an exception if asked to load an existing filename with no extension
DescriptionWhen #mod_use is used with an argument that names a file that exists, and the name has no extension, the toplevel will die with an exception:

  Fatal error: exception Invalid_argument("Filename.chop_extension")

Note that this does not happen if the named file does not exist.
Steps To Reproduce$ touch wat
$ ocaml
        OCaml version 4.06.1

# #mod_use "wat";;
Fatal error: exception Invalid_argument("Filename.chop_extension")
$
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0019425)
gasche (administrator)
2018-10-26 10:07

Nice catch. Would you like to provide a patch to fix this issue?

(It might be necessary to duplicate the fix for the native toplevel as well, see files toplevel/opttop*.)
(0019430)
ggole (reporter)
2018-10-26 20:20

Hmm, is changing Filename.chop_extension to Filename.remove_extension sufficient? It seems as if that will avoid raising the exception.

The code (specifically parse_mod_use_file) seems a bit suspicious to me. A module name is supposed to be generated from a filename, but strings that are not sane module names such as "@%" are allowed. In fact, fairly sane filenames like "foo-bar.ml" will "work" and produce a module that the user will not be able to name in OCaml code - that doesn't seem right.

I would guess that a module name should be parsed after whacking off the filename parts?
(0019431)
gasche (administrator)
2018-10-26 22:18

For the record, the relevant code is:

let parse_mod_use_file name lb =
  let modname =
    String.capitalize_ascii (Filename.chop_extension (Filename.basename name))
  in ...

Clearly the intent of the modname calculation is to turn a valid filename into a valid module name, and as you say it does not work very well. I don't think a robust logic exists to do this name munging inside the compiler (debugger/command_line.ml has similar but more robust logic in convert_module).

If you feel inspired to write something more robust, I think it could go into utils/misc.ml. If you don't, then I think at least getting rid of the failure here would be nice. Indeed Filename.remove_extension should be enough, I guess it did not exist at the time parse_mod_use_file was written.
(0019432)
ggole (reporter)
2018-10-27 07:47

All right, I made a PR with that simple change.

- Issue History
Date Modified Username Field Change
2018-10-26 09:53 ggole New Issue
2018-10-26 10:07 gasche Note Added: 0019425
2018-10-26 16:39 gasche Status new => feedback
2018-10-26 20:20 ggole Note Added: 0019430
2018-10-26 20:20 ggole Status feedback => new
2018-10-26 22:18 gasche Note Added: 0019431
2018-10-27 07:47 ggole Note Added: 0019432
2018-10-27 17:32 gasche Status new => resolved
2018-10-27 17:32 gasche Fixed in Version => 4.08.0+dev
2018-10-27 17:32 gasche Resolution open => fixed
2018-10-27 17:32 gasche Assigned To => gasche


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker