WeaselJsonParser_reset is documented in include/weaseljson.h line 60 as restoring the parser to its newly-created state, but Parser3::reset() in src/parser3.h (line 138) only resets the symbol stack. It does not reset the inKey member (declared at line 157), so transient key/string state from the previous parse leaks into the next parse.
Impact: if a chunk ends while the parser is inside an object key, the parser leaves inKey == true. After WeaselJsonParser_reset, a subsequent top-level string value is delivered through on_key_data instead of on_string_data.
Reproducer:
auto*p=WeaselJsonParser_create(1024,&callbacks,nullptr,0);WeaselJsonParser_parse(p,"{\"ab",4);// returns AGAIN, parser is mid-key
WeaselJsonParser_reset(p);WeaselJsonStatusr=WeaselJsonParser_parse(p,"\"hello\"",7);if(r==WeaselJson_AGAIN)r=WeaselJsonParser_parse(p,nullptr,0);// r == WeaselJson_OK, but callbacks receive "abhello" via on_key_data,
// not "hello" via on_string_data.
Expected behavior: reset() should set inKey = false and clear any other per-parse transient state (e.g. utf8Codepoint, utf16Surrogate, numDfa, strDfa) so that the next document starts from the same state as a newly created parser.
Files/lines:
src/parser3.h:138 — reset() implementation
src/parser3.h:157 — bool inKey = false;
src/lib.cpp:31-32 — C wrapper calling reset()
include/weaseljson.h:59-60 — contract comment
`WeaselJsonParser_reset` is documented in `include/weaseljson.h` line 60 as restoring the parser to its newly-created state, but `Parser3::reset()` in `src/parser3.h` (line 138) only resets the symbol stack. It does not reset the `inKey` member (declared at line 157), so transient key/string state from the previous parse leaks into the next parse.
Impact: if a chunk ends while the parser is inside an object key, the parser leaves `inKey == true`. After `WeaselJsonParser_reset`, a subsequent top-level string value is delivered through `on_key_data` instead of `on_string_data`.
Reproducer:
```cpp
auto *p = WeaselJsonParser_create(1024, &callbacks, nullptr, 0);
WeaselJsonParser_parse(p, "{\"ab", 4); // returns AGAIN, parser is mid-key
WeaselJsonParser_reset(p);
WeaselJsonStatus r = WeaselJsonParser_parse(p, "\"hello\"", 7);
if (r == WeaselJson_AGAIN) r = WeaselJsonParser_parse(p, nullptr, 0);
// r == WeaselJson_OK, but callbacks receive "abhello" via on_key_data,
// not "hello" via on_string_data.
```
Expected behavior: `reset()` should set `inKey = false` and clear any other per-parse transient state (e.g. `utf8Codepoint`, `utf16Surrogate`, `numDfa`, `strDfa`) so that the next document starts from the same state as a newly created parser.
Files/lines:
- `src/parser3.h:138` — `reset()` implementation
- `src/parser3.h:157` — `bool inKey = false;`
- `src/lib.cpp:31-32` — C wrapper calling `reset()`
- `include/weaseljson.h:59-60` — contract comment
weaselbot
was assigned by andrew2026-06-18 14:05:32 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
WeaselJsonParser_resetis documented ininclude/weaseljson.hline 60 as restoring the parser to its newly-created state, butParser3::reset()insrc/parser3.h(line 138) only resets the symbol stack. It does not reset theinKeymember (declared at line 157), so transient key/string state from the previous parse leaks into the next parse.Impact: if a chunk ends while the parser is inside an object key, the parser leaves
inKey == true. AfterWeaselJsonParser_reset, a subsequent top-level string value is delivered throughon_key_datainstead ofon_string_data.Reproducer:
Expected behavior:
reset()should setinKey = falseand clear any other per-parse transient state (e.g.utf8Codepoint,utf16Surrogate,numDfa,strDfa) so that the next document starts from the same state as a newly created parser.Files/lines:
src/parser3.h:138—reset()implementationsrc/parser3.h:157—bool inKey = false;src/lib.cpp:31-32— C wrapper callingreset()include/weaseljson.h:59-60— contract comment