Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking modules compiled with -labels and -nolabels is not safe #7432

Closed
vicuna opened this Issue Dec 15, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@vicuna
Copy link
Collaborator

vicuna commented Dec 15, 2016

Original bug ID: 7432
Reporter: @yallop
Assigned to: @garrigue
Status: resolved (set by @garrigue on 2016-12-17T01:38:18Z)
Resolution: fixed
Priority: normal
Severity: minor
Fixed in version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Category: typing
Monitored by: @hcarty

Bug description

The -labels and -nolabels modes of the compiler have different views of type equality. There are some types that are considered equal with -nolabels, but incompatible with -labels.

It's possible, therefore, to pass a witness of type equality (compiled with -nolabels) to a function compiled (with -labels) under the assumption that no such witness can exist, leading to a crash.

Here's a demonstration:

$ cat a.ml 
type (_,_) eql = Refl : ('a, 'a) eql
type s = x:int -> y:float -> unit
type t = y:int -> x:float -> unit
let eql : (s, t) eql = Refl
$ cat b.ml 
open A

type silly = {silly: 'a.'a}

let f : [`L of (s, t) eql | `R of silly] -> 'a =
   function `R {silly} -> silly
let () = print_endline (f (`L A.eql))
$ ocamlopt -c -nolabels a.ml  && ocamlopt -c  b.ml && ocamlopt a.cmx b.cmx -o a.out
$ ./a.out 
Segmentation fault
@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Dec 17, 2016

Comment author: @garrigue

Fixed by commit 6e694c6.

mcomp was already doing the right thing (ignoring labels for non-optional arguments), but unify has to do the same thing when in Pattern mode.

@vicuna vicuna closed this Dec 17, 2016

@vicuna vicuna added the typing label Mar 14, 2019

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.