Ignore CBOR tags 0-5 and 21-23 (head bytes 0xC0-0xC5, 0xD5-0xD7) - #5367
Ignore CBOR tags 0-5 and 21-23 (head bytes 0xC0-0xC5, 0xD5-0xD7)#5367MsfPablo wants to merge 1 commit into
Conversation
Every byte in 0xC0-0xDB is major type 6 (tag), but the switch in parse_cbor_internal() only enumerated 0xC6-0xD4 and 0xD8-0xDB. Head bytes 0xC0-0xC5 and 0xD5-0xD7 fell through to default: and were reported as parse_error.112 in every handler mode, including ignore and store. Add the missing head bytes to the tagged-item case list so they are handled exactly like tags 6-20: error still throws, ignore skips the tag head and parses the enclosed data item, store parses it without a subtype. No tag is interpreted. Fixes nlohmann#5315
|
Apologies for the AI-assisted review here — I don't have time for a deeper pass on this one right now, so this is a quick comparison rather than a full re-review. This duplicates #5331, which has the identical code fix and was opened first. Your docs update here is actually better — it removes the stale "Incomplete mapping" bullets that #5331 left contradicting the paragraph right below it — but this PR is currently missing a Neither PR yet adds the test coverage requested on #5331 (a Given #5331 is further along (green CI, already reviewed), we'll likely take that one as the base and fold in the docs fix from here. Thanks for the contribution either way — closing this in favor of #5331 once that's updated, unless you'd rather rebase your docs fix onto it yourself. — posted by Claude Code on behalf of @nlohmann |
The "Incomplete mapping" warning still listed tags 0-5 (date/time, bignum, decimal fraction, bigfloat) and 21-23 (expected conversions) as unsupported, even though they now parse correctly under cbor_tag_handler_t::ignore/store, same as 0xC6..0xD4/0xD8..0xDB. Remove those five bullets and cross-reference the "Tagged items" warning below, matching the equivalent docs fix landed independently in PR nlohmann#5367. Also add a cbor_tag_handler_t::store test that wraps a binary payload (not just a string) for every byte in 0xC0..0xD7, confirming these tags are unwrapped the same way as 0xC6..0xD4 rather than mistaken for the 0xD8..0xDB binary-subtype marker syntax, per review feedback on nlohmann#5331. Signed-off-by: sahilkamate03 <45514385+sahilkamate03@users.noreply.github.com>
The "Incomplete mapping" warning still listed tags 0-5 (date/time, bignum, decimal fraction, bigfloat) and 21-23 (expected conversions) as unsupported, even though they now parse correctly under cbor_tag_handler_t::ignore/store, same as 0xC6..0xD4/0xD8..0xDB. Remove those five bullets and cross-reference the "Tagged items" warning below, matching the equivalent docs fix landed independently in PR nlohmann#5367. Also add a cbor_tag_handler_t::store test that wraps a binary payload (not just a string) for every byte in 0xC0..0xD7, confirming these tags are unwrapped the same way as 0xC6..0xD4 rather than mistaken for the 0xD8..0xDB binary-subtype marker syntax, per review feedback on nlohmann#5331. Signed-off-by: sahilkamate03 <45514385+sahilkamate03@users.noreply.github.com>
The "Incomplete mapping" warning still listed tags 0-5 (date/time, bignum, decimal fraction, bigfloat) and 21-23 (expected conversions) as unsupported, even though they now parse correctly under cbor_tag_handler_t::ignore/store, same as 0xC6..0xD4/0xD8..0xDB. Remove those five bullets and cross-reference the "Tagged items" warning below, matching the equivalent docs fix landed independently in PR nlohmann#5367. Also add a cbor_tag_handler_t::store test that wraps a binary payload (not just a string) for every byte in 0xC0..0xD7, confirming these tags are unwrapped the same way as 0xC6..0xD4 rather than mistaken for the 0xD8..0xDB binary-subtype marker syntax, per review feedback on nlohmann#5331. Signed-off-by: sahilkamate03 <45514385+sahilkamate03@users.noreply.github.com>
The "Incomplete mapping" warning still listed tags 0-5 (date/time, bignum, decimal fraction, bigfloat) and 21-23 (expected conversions) as unsupported, even though they now parse correctly under cbor_tag_handler_t::ignore/store, same as 0xC6..0xD4/0xD8..0xDB. Remove those five bullets and cross-reference the "Tagged items" warning below, matching the equivalent docs fix landed independently in PR nlohmann#5367. Also add a cbor_tag_handler_t::store test that wraps a binary payload (not just a string) for every byte in 0xC0..0xD7, confirming these tags are unwrapped the same way as 0xC6..0xD4 rather than mistaken for the 0xD8..0xDB binary-subtype marker syntax, per review feedback on nlohmann#5331. Signed-off-by: sahilkamate03 <45514385+sahilkamate03@users.noreply.github.com>
Fixes #5315.
Every byte in
0xC0–0xDBis major type 6 (tag), but theswitchinparse_cbor_internal()enumerated only0xC6–0xD4and0xD8–0xDB. Head bytes0xC0–0xC5and0xD5–0xD7fell through todefault:and were reported asparse_error.112in every handler mode, includingignoreandstore.This adds the missing head bytes to the tagged-item case list, so they are handled exactly like tags 6–20 already are:
cbor_tag_handler_t::error(the default) still throws — unchanged.ignoreskips the tag head and parses the enclosed data item.storeparses the enclosed item; as with tags 6–20, no subtype is recorded (only the0xD8–0xDBforms carry one today).No tag is interpreted: a text string tagged 0 stays a string,
0xC2over a byte string stays a byte string.Changes
include/nlohmann/detail/input/binary_reader.hpp(and the amalgamated header): addcase 0xC0–0xC5andcase 0xD5–0xD7to the tagged-item block.tests/src/unit-cbor.cpp: the "Tagged values" section that swept0xC6..0xD4now sweeps0xC0..0xD7, asserting throw inerrormode and the original value inignore/storemode for each head byte.docs/.../cbor.md: the "Incomplete mapping" list no longer claims tags 0–5 and 21–23 are unsupported; the tagged-items note now states the range and that tags are skipped, not interpreted.The "all CBOR first bytes" test needed no change — it parses in the default
errormode, where these bytes still throwparse_error.112.Verification
test-cbor_cpp11passes (the only failures in my local run are the test cases requiring the downloaded test-data fixtures, which I did not fetch). The reproduction from the issue now works:and a sweep of
0xC0–0xD7confirms every head byte throws inerrormode and yields the enclosed value inignoreandstoremode.