cap recursion depth in yaml and toml generic value readers#2660
Closed
uwezkhan wants to merge 1 commit into
Closed
cap recursion depth in yaml and toml generic value readers#2660uwezkhan wants to merge 1 commit into
uwezkhan wants to merge 1 commit into
Conversation
Owner
Contributor
Author
|
Sounds good, thanks for folding it in. #2662 covers more of the recursive paths than my version did, the dotted-key/table-header descent and skip_flow_content were both reachable and I'd only guarded the variant choke point. Collapsing onto one shared depth_guard is cleaner too. Happy with this landing in #2662. |
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.
The YAML and TOML readers parse a generic value by dispatching on the first byte and recursing back through the variant reader for each nested element. Block-style nesting is bounded by the indent stack, but flow collections (
[ ],{ }) and TOML arrays never touch that stack, so they recurse one level per opening bracket with nothing counting depth. A document that is a few thousand[therefore overflows the call stack and crashes (SIGSEGV) when read intoglz::generic, which is reachable from any untrusted YAML or TOML input.Before, flow nesting could only stop at the stack limit. After, the variant reader (the single point every nested generic value passes through) takes the same
depth_guardthe BSON and JSONB readers already use, so a value nested pastmax_recursive_depth_limitreturnsexceeded_max_recursive_depthrather than recursing further. Guarding the variant reader instead of each container parser keeps it to one site per format and also covers the block mappings reached from flow context, which the indent stack alone misses. The cost is a fixed 256 level cap on generic values, the same limit the block parsers and the binary readers already enforce.