Skip to content

[C++] Reset ParseJson field stack between documents - #9241

Open
Parcifalix00 wants to merge 1 commit into
google:masterfrom
Parcifalix00:fix-parsejson-field-stack-reset
Open

Parcifalix00 wants to merge 1 commit into
google:masterfrom
Parcifalix00:fix-parsejson-field-stack-reset

Conversation

@Parcifalix00

Copy link
Copy Markdown

Summary

Parser::ParseJson() clears builder_ before parsing a new JSON document, but
does not clear field_stack_.

If malformed JSON causes vector parsing to return early, temporary entries can
remain in field_stack_. Reusing the same Parser for subsequent independent
ParseJson() calls can therefore accumulate parser state across documents.

This change clears field_stack_ at the same independent-document boundary as
builder_.

Regression test

The regression test reuses one Parser across malformed JSON vector parses and
verifies that temporary field_stack_ entries do not accumulate across calls.
It also verifies that a subsequent valid JSON document leaves the stack empty.

The identical test fails on the previous implementation and passes with this
change.

Impact

Long-lived integrations that recover from JSON parse errors and reuse a
Parser can otherwise retain temporary state across independent inputs. With
repeated malformed inputs this can produce cumulative process-memory growth and,
under a finite memory budget, eventual resource exhaustion.

This change addresses parser-state retention and availability/resource
exhaustion. It does not claim memory corruption, confidentiality or integrity
impact, privilege escalation, or code execution.

Validation

  • Deterministic regression: fails before the fix and passes after it.
  • Configured CTest suite: passes.
  • git diff --check: clean.
  • C++ formatting validation: passes.

Clear temporary field_stack_ state before parsing each independent JSON
document and add a regression test for failed-vector parser reuse.
@google-cla

google-cla Bot commented Sep 13, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added c++ codegen Involving generating code from schema labels Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant