patch nesting depth issue#166
Open
farhanfarasdak wants to merge 2 commits into
Open
Conversation
added 2 commits
June 27, 2026 21:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is no limit on nesting depth anywhere in the decode path. A grep for depth/nesting/10000 in the package matches only the encoder's pointer-cycle counter and the streaming tokenizer — nothing guards decode recursion. The standard library it replaces deliberately caps this at maxNestingDepth = 10000 and returns an error
Case like this possible :
An attacker sends a tiny, highly-repetitive body — e.g. ~5,000,000 [ characters followed by ] (about 10 MB, trivially gzip-compressible to a few KB over the wire). Decoding it drives ~5,000,000 nested calls and pushes the goroutine stack past Go's hard limit (1 GiB), producing fatal error: stack overflow / runtime: goroutine stack exceeds 1000000000-byte limit. Crucially this is not a recoverable panic: a Go stack overflow is a fatal runtime error that recover() cannot intercept (and the package has no recover() anyway), so the entire process dies — not just the request goroutine.