ANTLR3 C target runs into infinite loop for input starting with NULL byte
- Dominant language
- Java
- Stars
- 253
- Forks
- 178
- PR merge metrics
- No merged PRs in 30d
Description
I'm not sure whether it is a lexer or parser issue, but giving an input starting with a NULL byte to be parsed by the attached grammar result into an infinite loop.
Looking at the looping process with gdb yields the following stack trace:
```
0x00000037d7011bf8 in get (ts=, i=1592905172)
at src/antlr3tokenstream.c:503
503 return (pANTLR3_COMMON_TOKEN)(cts->tokens->get(cts->tokens, i)); /* Token index is zero based but vectors are 1 based */
(gdb) up
#1 0x00000037d7012100 in toStringSS (ts=0x1248320, start=,
stop=4294967295) at src/antlr3tokenstream.c:566
566 tok = ts->get(ts, i);
(gdb)
#2 0x000000000040c647 in throwEvalQueryException (recognizer=0x12485a0,
tokenNames=0x6a9500 ) at cqpeval.cc:200
200 ttext = parser->tstream->toStringTT(parser->tstream, theToken, theToken);
(gdb)
#3 0x0000000000418760 in seq (ctx=ctx@entry=0x12862f0) at cqpParser.cc:3850
3850 PREPORTERROR();
(gdb)
#4 0x00000000004189c0 in sequence (ctx=ctx@entry=0x12862f0) at cqpParser.cc:3559
3559 seq55=seq(ctx);
(gdb)
#5 0x0000000000418f90 in query (ctx=0x12862f0) at cqpParser.cc:1007
1007 sequence1=sequence(ctx);
(gdb)
#6 0x000000000040bf4c in eval_cqpquery (query=, corp=corp@entry=
0x7fff44f74070) at cqpeval.cc:47
47 cqpParser_query_return cqpAST = parser->query(parser);
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with src/antlr3tokenstream.c, especially get and toStringSS, using the reported gdb stack trace and the attached grammar to reproduce the loop on input beginning with a NULL byte. Compare the call from cqpeval.cc and verify that parsing this input terminates without looping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100