Fix BSON conformance issue#5185
Open
nlohmann wants to merge 3 commits into
Open
Conversation
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
nlohmann
commented
May 19, 2026
Comment on lines
+314
to
+323
| { | ||
| { | ||
| 0.0L, -0.0L, 1.0L, -1.0L, | ||
| 0.5L, -0.5L, 1.5L, -2.25L, | ||
| 1.23e45L, 1.23e-45L, | ||
| (std::numeric_limits<long double>::min)(), | ||
| std::numeric_limits<long double>::lowest(), | ||
| (std::numeric_limits<long double>::max)() | ||
| } | ||
| }; |
Owner
Author
There was a problem hiding this comment.
Note: This is an unrelated whitespace change that was done by astyle.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
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.
Summary
Fixes two BSON specification conformance issues in
nlohmann::json::from_bson():int32document_sizeat the start of a BSON document or arrayis now enforced as a boundary. Documents with
document_size < 5arerejected, and parsing must end exactly at the declared boundary (after
consuming the trailing
0x00document terminator).0x02)is now required to be
0x00. Previously any non-EOF byte was accepted.Changes
include/nlohmann/detail/input/binary_reader.hppparse_bson_internal(),parse_bson_array(): validatedocument_size >= 5; track the document start position; verify parsingconsumes exactly
document_sizebytes.get_bson_string(): require the terminator byte to be0x00.tests/src/unit-bson.cpp: regression tests covering the newly-rejectedinputs.
Notes
The binary-format readers (
from_bson,from_cbor,from_msgpack,from_ubjson,from_bjdata) are not designed to validate untrusted input.An attacker who can submit bytes to
from_bson()can already cause arbitraryJSON values to be returned via a spec-conformant payload. These changes close
conformance gaps that should be enforced regardless.
A GitHub Security Advisory will be published referencing this PR.
Reported by @manop55555.