Documentation review: exceptions from binary-format hardening, and tuple reference types - #5359
Merged
Conversation
A round of binary-format input validation (#5274, #5284, #5287, #5332) added new failure modes without updating exceptions.md, and left two descriptions factually narrower than the code: - parse_error.110 said "CBOR or MessagePack"; BSON and UBJSON also throw it. Generalized, and added the BSON EOF example (#5332). - parse_error.112: added the BSON document-size mismatch example (#5287). - parse_error.113 said "while parsing a map key", but its own existing UBJSON char example already contradicted that. Broadened to cover invalid length specifications, and added the negative-string-length example (#5284). - out_of_range.408 said "of an UBJSON array or object"; CBOR now throws it too (#5274). Generalized and added both CBOR examples. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
The note added in #5271 said a referenced type must be one the library stores "or an arithmetic type it can convert to/from". The parenthetical is wrong: is_compatible_reference_type requires an exact match against the stored types, so std::tuple<int&> is rejected by static_assert even though int converts fine as a value. Only the value case is permissive. Spell out the eight admissible types, give the int& counter-example, and separate the reference restriction from by-value conversion. 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
Documentation corrections found while auditing everything merged into
developsince #5271, and then re-reviewing the release-notes draft against the code.1. Exceptions from the binary-format hardening round. #5274, #5284, #5287 and #5332 added input-validation rejections; only #5314 updated
exceptions.md. Two entries had become claims the code contradicts:parse_error.110said "When parsing CBOR or MessagePack". BSON throws it as of check all BSON reads and add an EOF check for booleans #5332, and UBJSON already did — the entry's own example was a UBJSON message. Generalized; added the BSON EOF example.out_of_range.408said "The size (following#) of an UBJSON array or object". CBOR throws it as of reject CBOR array/map length equal to the indefinite-length marker #5274. Generalized; added both CBOR examples.parse_error.113said "While parsing a map key" — already contradicted by its own UBJSON-charexample. Broadened to cover invalid length specifications; added the negative-string-length example.parse_error.112: added the BSON document-size-mismatch example (validate BSON document size against the bytes read #5287).2. Which types may be referenced in a tuple extraction. The note I added in #5271 said a referenced type must be one the library stores "or an arithmetic type it can convert to/from". That parenthetical is wrong:
is_compatible_reference_typerequires an exact match against the stored types, sostd::tuple<int&>is rejected bystatic_assert— the library storesnumber_integer_t(std::int64_t), and there is nointto bind to. Only the by-value case is permissive. Corrected to list the eight admissible types, give theint&counter-example, and separate the two cases.Does this break the public API?
No. Documentation-only — no header, behavior, or ABI change.
Test plan
unit-bson.cpp,unit-cbor.cpp,unit-bjdata.cpp).binary_reader.hppondevelopfor which formats actually throw each code.is_compatible_reference_typeintype_traits.hppand thestatic_assertinfrom_json.hpp, cross-checked with the reference tests inunit-constructor1.cpp.🤖 Generated with Claude Code