Stop binary writers overflowing the stack on deep values - #5518
Open
ayush-singh-0601 wants to merge 1 commit into
Open
ayush-singh-0601 wants to merge 1 commit into
ayush-singh-0601 wants to merge 1 commit into
Conversation
to_cbor, to_msgpack, and to_ubjson recurse once per nesting level. The parser is iterative, so a value the library accepts can crash on the way back out. Keep the existing recursive path for the first 128 levels and finish anything deeper on a heap stack. Output is unchanged. BSON is left alone because its extra size walk is a separate change. See nlohmann#5392. Signed-off-by: ayush-singh-0601 <singhayush062006@gmail.com>
ayush-singh-0601
force-pushed
the
binary-writer-stack-overflow
branch
from
September 10, 2026 19:44
ead14ec to
7eb828e
Compare
nlohmann
requested changes
Sep 12, 2026
nlohmann
left a comment
Owner
There was a problem hiding this comment.
Please update from the develop branch.
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.
See #5392.
to_cbor,to_msgpack, andto_ubjsonrecurse once per nesting level. Parsing is iterative, so a value this library will happily build can still SIGSEGV when you serialize it.This keeps the current recursive write for the first 128 levels (normal documents) and finishes anything deeper on a heap stack. Encoding is the same.
BSON is not in this PR. Its writer also walks the tree a second time to compute document lengths, so that belongs with the size-pass work.
make amalgamate.