Skip to content

Skip data item when decoding to time.Time fails under certain conditions - #803

Merged
fxamacker merged 1 commit into
release-2.9from
fxamacker/fix-unmarshal-to-time
Aug 18, 2026
Merged

Skip data item when decoding to time.Time fails under certain conditions#803
fxamacker merged 1 commit into
release-2.9from
fxamacker/fix-unmarshal-to-time

Conversation

@fxamacker

Copy link
Copy Markdown
Owner

Refs #802

NOTE: This issue does not affect standard CBOR time data (RFC 8949 tag 0 or tag 1) because the decoder already skips those data items on error. Setting timeTag = DecTagRequired also avoids the issue.

When decoding into time.Time from a CBOR byte string, map, or array and decoding fails with UnmarshalTypeError, the data item at the cursor is not skipped under these decoding options:

  • CBOR byte string, if byteStringToTime == ByteStringToTimeForbidden and timeTag != DecTagRequired
  • CBOR array and map, if timeTag != DecTagRequired

Since the cursor is not advanced, a caller can encounter unrelated decoding errors or panic if they continue parsing the rest of the CBOR data.

This problem was identified while trying to reproduce the stack trace mentioned in issue #802.

This PR resolves the issue by skipping the data item under the above conditions, making it consistent with the other options and data types when decoding to time.Time.

NOTE: This issue does not affect standard CBOR time data
(RFC 8949 tag 0 or tag 1) because the decoder already skips
those data items on error.  Setting timeTag = DecTagRequired
also avoids the issue.

When decoding into time.Time from a CBOR byte string, map,
or array and decoding fails with UnmarshalTypeError, the data
item at the cursor is not skipped under these decoding options:
- CBOR byte string, if byteStringToTime == ByteStringToTimeForbidden
  and timeTag != DecTagRequired
- CBOR array and map, if timeTag != DecTagRequired

Since the cursor is not advanced, a caller can encounter unrelated
decoding errors or panic if they continue parsing the rest of the
CBOR data.

This commit resolves the issue by skipping the data item under the
above conditions, making it consistent with the other options and
data types when decoding to time.Time.
@fxamacker fxamacker self-assigned this Aug 18, 2026
@fxamacker

fxamacker commented Aug 18, 2026

Copy link
Copy Markdown
Owner Author

@x448 PTAL 🙏 I updated fuzz tests to check for this issue and it passed limited fuzzing today with this PR (I will continue fuzzing v2.9.3 after release tagging).

@x448 x448 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. I only reviewed non-test code.

@fxamacker
fxamacker merged commit f0c90b6 into release-2.9 Aug 18, 2026
25 checks passed
This was referenced Aug 18, 2026
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