Skip to content

Ignore CBOR tags 0-5 and 21-23 (head bytes 0xC0-0xC5, 0xD5-0xD7) - #5367

Open
MsfPablo wants to merge 1 commit into
nlohmann:developfrom
MsfPablo:fix/cbor-tag-ignore-5315
Open

Ignore CBOR tags 0-5 and 21-23 (head bytes 0xC0-0xC5, 0xD5-0xD7)#5367
MsfPablo wants to merge 1 commit into
nlohmann:developfrom
MsfPablo:fix/cbor-tag-ignore-5315

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Aug 7, 2026

Copy link
Copy Markdown

Fixes #5315.

Every byte in 0xC00xDB is major type 6 (tag), but the switch in parse_cbor_internal() enumerated only 0xC60xD4 and 0xD80xDB. Head bytes 0xC00xC5 and 0xD50xD7 fell through to default: and were reported as parse_error.112 in every handler mode, including ignore and store.

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.
  • ignore skips the tag head and parses the enclosed data item.
  • store parses the enclosed item; as with tags 6–20, no subtype is recorded (only the 0xD80xDB forms carry one today).

No tag is interpreted: a text string tagged 0 stays a string, 0xC2 over a byte string stays a byte string.

Changes

  • include/nlohmann/detail/input/binary_reader.hpp (and the amalgamated header): add case 0xC00xC5 and case 0xD50xD7 to the tagged-item block.
  • tests/src/unit-cbor.cpp: the "Tagged values" section that swept 0xC6..0xD4 now sweeps 0xC0..0xD7, asserting throw in error mode and the original value in ignore/store mode 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 error mode, where these bytes still throw parse_error.112.

Verification

test-cbor_cpp11 passes (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:

{"t":"2026-07-27T00:00:00Z"}

and a sweep of 0xC00xD7 confirms every head byte throws in error mode and yields the enclosed value in ignore and store mode.

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
@nlohmann

nlohmann commented Aug 7, 2026

Copy link
Copy Markdown
Owner

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 Signed-off-by trailer, so the DCO check is failing and will block merge as-is.

Neither PR yet adds the test coverage requested on #5331 (a store-mode test with a binary payload, not just a string, to confirm 0xC0-0xC5/0xD5-0xD7 take the same "unwrap, don't treat as subtype" path as the existing tag range).

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

sahilkamate03 added a commit to fork-of-sahil/json that referenced this pull request Aug 7, 2026
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>
sahilkamate03 added a commit to fork-of-sahil/json that referenced this pull request Aug 7, 2026
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>
sahilkamate03 added a commit to fork-of-sahil/json that referenced this pull request Aug 7, 2026
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>
sahilkamate03 added a commit to fork-of-sahil/json that referenced this pull request Aug 10, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CBOR: cbor_tag_handler_t::ignore does not ignore tags 0-5 and 21-23 (head bytes 0xC0-0xC5, 0xD5-0xD7)

2 participants