You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 4966 Reporter: bluestorm Assigned to: ertai Status: closed (set by @xavierleroy on 2012-09-25T18:07:21Z) Resolution: fixed Priority: normal Severity: minor Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues Monitored by:@gasche
Bug description
The ignore_upto of the stream testers (ugly camlp4 hacks by themselves) are faulty : they do not handle the "EOI" token gracefully, leading in some case to diverging loops.
Camlp4ListComprehension and Camlp4OCamlParser are affected, 3.10, 3.11 and Ocaml SVN trunk. See "additional information" for tests and a fix.
Additional information
Here is a two-lines (incorrect) caml code leading to an infinite loop when parsed by camlp4o :
class type foo = object end
class test : [int -> foo = fun n -> object end
The loops is caused by the "[" : at this syntaxic position is a "test_ctyp_minusgreater" stream test, using the faulty "ignore-upto" function.
Here is the faulty ignore_upto code :
and ignore_upto end_kwd n =
match stream_peek_nth n strm with
[ Some (KEYWORD prm) when prm = end_kwd -> n
| Some (KEYWORD ("[" | "[<")) ->
ignore_upto end_kwd (ignore_upto "]" (n + 1) + 1)
| Some (KEYWORD "(") -> ignore_upto end_kwd (ignore_upto ")" (n + 1) + 1)
| Some _ -> ignore_upto end_kwd (n + 1)
| None -> raise Stream.Failure ]
in
Here is a (hopefully) correct fix :
and ignore_upto end_kwd n =
match stream_peek_nth n strm with
[ Some (KEYWORD prm) when prm = end_kwd -> n
| Some (KEYWORD ("[" | "[<")) ->
ignore_upto end_kwd (ignore_upto "]" (n + 1) + 1)
| Some (KEYWORD "(") ->
ignore_upto end_kwd (ignore_upto ")" (n + 1) + 1)
| Some (KEYWORD "{") ->
ignore_upto end_kwd (ignore_upto "}" (n + 1) + 1)
| None | Some EOI -> raise Stream.Failure
| Some _ -> ignore_upto end_kwd (n + 1) ]
The only change being the new (Some EOI) pattern.
This bug is also present in Camlp4ListComprehension, in wich the same ignore_upto code is reproduced verbatim. Here is a test:
camlp4o -parser Camlp4ListComprehension -str '[ x | (x <- l ]'
Same cause, same fix.
The faulty code is still present in Ocaml SVN trunk, so I suppose it wasn't fixed.
The bug was originally reported by Tiphaine Turpin on the "Batteries" project bug tracker : the buggy file, pa_comprehension.ml, use code borrowed from Camlp4ListComprehension.
The text was updated successfully, but these errors were encountered:
Original bug ID: 4966
Reporter: bluestorm
Assigned to: ertai
Status: closed (set by @xavierleroy on 2012-09-25T18:07:21Z)
Resolution: fixed
Priority: normal
Severity: minor
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues
Monitored by: @gasche
Bug description
The ignore_upto of the stream testers (ugly camlp4 hacks by themselves) are faulty : they do not handle the "EOI" token gracefully, leading in some case to diverging loops.
Camlp4ListComprehension and Camlp4OCamlParser are affected, 3.10, 3.11 and Ocaml SVN trunk. See "additional information" for tests and a fix.
Additional information
Here is a two-lines (incorrect) caml code leading to an infinite loop when parsed by camlp4o :
class type foo = object end
class test : [int -> foo = fun n -> object end
The loops is caused by the "[" : at this syntaxic position is a "test_ctyp_minusgreater" stream test, using the faulty "ignore-upto" function.
Here is the faulty ignore_upto code :
Here is a (hopefully) correct fix :
The only change being the new (Some EOI) pattern.
This bug is also present in Camlp4ListComprehension, in wich the same ignore_upto code is reproduced verbatim. Here is a test:
camlp4o -parser Camlp4ListComprehension -str '[ x | (x <- l ]'
Same cause, same fix.
The faulty code is still present in Ocaml SVN trunk, so I suppose it wasn't fixed.
The bug was originally reported by Tiphaine Turpin on the "Batteries" project bug tracker : the buggy file, pa_comprehension.ml, use code borrowed from Camlp4ListComprehension.
The text was updated successfully, but these errors were encountered: