antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.14k stars 3.28k forks source link

[Java] Infinite loop in parser #2815

Open oridool opened 4 years ago

oridool commented 4 years ago

Hi, I'm using the attached grammar. Query.txt

The parser is entering an infinite loop and eventually I get java.lang.OutOfMemoryError.

When trying to parse the text: releaseDate GE 2020-04-28T00:00:00 (without double quotes surrounding the date), the parser enters infinite loop.

When I parse the text: releaseDate "GE 2020-04-28T00:00:00" , (with double quotes surrounding the date), everything is OK.

I'm using latest antlr-4.8 and Java 11.

The infinite loop is in DefaultErrorStrategy.consumeUntil:

        while (ttype != Token.EOF && !set.contains(ttype) ) {
            //System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]);
//          recognizer.getInputStream().consume();
            recognizer.consume();
            ttype = recognizer.getInputStream().LA(1);
        }

Thank you.

ericvergnaud commented 4 years ago

Hi,

please move this to the google discussion group.

Thanks

Le 30 avr. 2020 à 06:02, Ori notifications@github.com a écrit :

Hi, I'm using the attached grammar. Query.txt https://github.com/antlr/antlr4/files/4554900/Query.txt The parser is entering an infinite loop and eventually I get java.lang.OutOfMemoryError.

When trying to parse the text: releaseDate GE 2020-04-28T00:00:00 (without double quotes surrounding the date), the parser enters infinite loop.

When I parse the text: releaseDate "GE 2020-04-28T00:00:00" , (with double quotes surrounding the date), everything is OK.

I'm using latest antlr-4.8 and Java 11.

The infinite loop is in DefaultErrorStrategy.consumeUntil:

  while (ttype != Token.EOF && !set.contains(ttype) ) {
        //System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]);

// recognizer.getInputStream().consume(); recognizer.consume(); ttype = recognizer.getInputStream().LA(1); } Thank you.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/antlr/antlr4/issues/2815, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZNQJHIIIQZABHVQXOM5QTRPCPZHANCNFSM4MUDHIZQ.