Skip to content

Add guard for depth overflow in ondemand parser#2662

Open
uwezkhan wants to merge 1 commit intosimdjson:masterfrom
uwezkhan:depth-overflow
Open

Add guard for depth overflow in ondemand parser#2662
uwezkhan wants to merge 1 commit intosimdjson:masterfrom
uwezkhan:depth-overflow

Conversation

@uwezkhan
Copy link
Copy Markdown
Contributor

@uwezkhan uwezkhan commented Apr 5, 2026

Adds a check in skip_child() to avoid overflow in depth tracking.

In extreme cases, the depth counter can overflow when parsing
deeply nested input. This adds a guard before incrementing it
and returns an error if the limit is reached.

@lemire
Copy link
Copy Markdown
Member

lemire commented Apr 5, 2026

Please demonstrate that an overflow is possible. I don't think it is.

@uwezkhan
Copy link
Copy Markdown
Contributor Author

uwezkhan commented Apr 5, 2026

You are right that this requires a very large and deeply nested input.

However the overflow is still reachable within the documented limits.
The depth counter is int32_t, and the maximum document size allows enough
characters to exceed INT32_MAX nesting levels .

In that case _depth will wrap and the condition in skip_child() can
evaluate incorrectly causing the function to return early while still
inside the structure.

I agree this is an extreme edge case. The change here is only
a small defensive guard before incrementing the counter, with no impact
on normal inputs.

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