Skip to content

Skip CBOR data item when destination struct has incorrect tags - #821

Merged
fxamacker merged 1 commit into
release-2.9from
fxamacker/release-2.9-skip-data-on-struct-tag-error
Sep 17, 2026
Merged

fxamacker merged 1 commit into
release-2.9from
fxamacker/release-2.9-skip-data-on-struct-tag-error

Conversation

@fxamacker

@fxamacker fxamacker commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

This issue is unlikely to be encountered in practice, because it requires user apps to use incorrect struct tags, which is detected on the first attempt to decode anything into the struct (i.e., during testing).

This PR skips the CBOR data item in parseArrayToStruct() and parseMapToStruct() if the destination struct has incorrect tags (e.g. struct tag specifies "keyasint" but struct field name cannot be parsed as an integer). Skipping the CBOR data item advances the data offset to the next CBOR data item so that the next CBOR data item can be parsed if needed.

The PR also includes the following changes in test code:

  • add test helper functions to check that Unmarshal() advances the data offset to the next CBOR data item on success and on error for well-formed CBOR data
  • update all relevant call sites in 6 test files to use the helper functions

This commit skips the CBOR data item in parseArrayToStruct() and
parseMapToStruct() if the destination struct has incorrect tags
(e.g. struct tag specifies "keyasint" but struct field name cannot
be parsed as an integer).  Skipping the CBOR data item advances the
data offset to the next CBOR data item so that the next CBOR data item
can be parsed if needed.

The commit also includes the following changes in test code:
- add test helper functions to check that Unmarshal() advances the
  data offset to the next CBOR data item on success and on error for
  well-formed CBOR data
- update all relevant call sites in 6 test files to use the helper
  functions
@fxamacker fxamacker self-assigned this Sep 16, 2026
@fxamacker
fxamacker merged commit 2bea028 into release-2.9 Sep 17, 2026
25 checks passed
fxamacker added a commit that referenced this pull request Sep 18, 2026
@fxamacker
fxamacker deleted the fxamacker/release-2.9-skip-data-on-struct-tag-error branch October 1, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants