Skip to content

Reset all per-parse state in JSON::ResumableParser#clear#1020

Merged
byroot merged 1 commit into
ruby:masterfrom
mame:fix-resumable-parser-state-reset
Jun 18, 2026
Merged

Reset all per-parse state in JSON::ResumableParser#clear#1020
byroot merged 1 commit into
ruby:masterfrom
mame:fix-resumable-parser-state-reset

Conversation

@mame

@mame mame commented Jun 18, 2026

Copy link
Copy Markdown
Member

Currently, #clear does not reset current_nesting.

require "json"
parser = JSON::ResumableParser.new(max_nesting: 10)
10.times do
  parser << "[1"
  parser.parse
  parser.clear
end
parser << "[1"
parser.parse   # JSON::NestingError: nesting of 11 is too deep

This PR resets current_nesting.
It also resets in_array and emitted_deprecations just for case, though I am not sure whether we should reset emitted_deprecations or not.

Comment on lines +2480 to +2482
parser->state.current_nesting = 0;
parser->state.in_array = 1;
parser->state.emitted_deprecations = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just memset(parser, 0, sizeof(*parser)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess not. Because then we need to be careful not to leak the buffers we allocated etc. Nevermind.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@byroot byroot force-pushed the fix-resumable-parser-state-reset branch from c40813e to 89ad4c8 Compare June 18, 2026 17:27
@byroot byroot merged commit 56d16de into ruby:master Jun 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants