fix: lower TOML_MAX_NESTED_VALUES to prevent stack overflow on deeply nested arrays/inline tables#293
Merged
marzer merged 1 commit intomarzer:masterfrom Mar 23, 2026
Conversation
…zer builds
Deeply nested arrays ([[[...) or inline tables ({a={b={c=...) cause
parse_array/parse_inline_table recursion that overflows the stack before
the existing TOML_MAX_NESTED_VALUES limit (256) is reached in
sanitizer-instrumented builds (ASAN/MSAN), where each recursion cycle
consumes ~3KB of stack.
Lower the default from 256 to 128. At 128 levels the worst-case stack
usage is ~420KB, leaving ample headroom on 1MB stacks even under ASAN.
No real TOML document needs 128 levels of container nesting.
Also add a regression test for deeply nested inline tables (arrays were
already covered by the issues/100 test).
Fixes marzer#292
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
marzer
approved these changes
Mar 23, 2026
Owner
marzer
left a comment
There was a problem hiding this comment.
Thanks!
Though, please do not use AI to write issues and PR descriptions on any future contributions to this repository. I would much rather read something written by a human, than obvious AI prose filled with bad markdown syntax and unicode abuse.
Contributor
Author
Go it! Thanks! |
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.
What does this change do?
Lowers the default \TOML_MAX_NESTED_VALUES\ from 256 to 128 to prevent stack overflows when parsing deeply nested arrays ([[[[...) or inline tables ({a={b={c=...).
Each recursion cycle in \parse_array\ → \parse_value\ → \parse_array\ (and the equivalent \parse_inline_table\ path) consumes ~3,280 bytes of stack. At the previous default of 256:
At the new default of 128:
PR #242 fixed a similar stack overflow for deeply nested dotted keys — this addresses the remaining array/inline table recursion path.
Fixes #292
Is it related to an existing bug report or feature request?
Yes — #292
Pre-merge checklist