Skip to content

CBOR store: fall back to ignore for non-binary tagged items - #5383

Open
ameliabarnabyhub wants to merge 3 commits into
nlohmann:developfrom
ameliabarnabyhub:fix/cbor-store-nonbinary-tag-fallback-5316
Open

CBOR store: fall back to ignore for non-binary tagged items#5383
ameliabarnabyhub wants to merge 3 commits into
nlohmann:developfrom
ameliabarnabyhub:fix/cbor-store-nonbinary-tag-fallback-5316

Conversation

@ameliabarnabyhub

Copy link
Copy Markdown

Fixes #5316 (part 1)

cbor_tag_handler_t::store assumed every tagged item is a byte string. Tagged maps, arrays, and other non-binary values therefore failed with parse_error.113 even though ignore accepted the same input (notably CBOR self-describe tag 55799).

When the tagged item is not a binary head byte, fall back to ignore parsing instead of forcing binary decoding. Binary tags still store the subtype as before.

Does not change behavior for tag numbers 6–20 over binary strings (part 2 of #5316).

Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated and/or formatted correctly.

📎 A ready-to-apply patch is attached to the failed workflow run as the amalgamation-patch artifact. Download it, then apply it locally from the repository root with:

git apply amalgamation.patch

This does not require installing astyle yourself.

@nlohmann nlohmann left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found two correctness issues while reviewing this PR:

1. single_include/nlohmann/json.hpp has diverged from include/ (most severe — likely root cause of the CI failures)

The amalgamation commit adds new logic (throw_on_discarded(), assert_msgpack_size(), discarded values now throwing type_error.318 instead of producing empty output) that never landed in include/nlohmann/detail/output/binary_writer.hpp. That header still has the old break;/JSON_ASSERT(false) paths — confirmed against develop and against this PR's diff, which only touches binary_reader.hpp, single_include/json.hpp, and tests/src/unit-cbor.cpp, never binary_writer.hpp.

Since the test suite compiles against include/, the updated discarded-value tests in tests/src/unit-cbor.cpp (expecting CHECK_THROWS_WITH_AS(...type_error.318...)) can't pass. This lines up with essentially every CI check failing on this PR, including ci_test_amalgamation.

2. The CBOR fix itself has a nested-tag regression

In include/nlohmann/detail/input/binary_reader.hpp (~line 904), the fallback for a non-binary tagged item under store mode hardcodes:

return parse_cbor_internal(false, cbor_tag_handler_t::ignore);

instead of propagating the enclosing tag_handler (which is store here). So tag(100) -> [tag(80) -> h'01'] parsed under store mode loses the inner tag's subtype, because everything inside the non-binary wrapper now gets parsed with ignore instead of store. Passing tag_handler through instead of the literal ignore should fix this without changing the intended behavior for the top-level non-binary tag.


Posted by Claude Code on behalf of @nlohmann.

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::store rejects documents that ignore accepts, and drops tag numbers 6-20

2 participants