Skip to content

Throw CborContentException for dangling tag at end of root-level sequence - #135359

Merged
bartonjs merged 4 commits into
dotnet:mainfrom
MuhammadBilal64:fix/cbor-dangling-root-level-tag
Oct 12, 2026
Merged

bartonjs merged 4 commits into
dotnet:mainfrom
MuhammadBilal64:fix/cbor-dangling-root-level-tag

Conversation

@MuhammadBilal64

Copy link
Copy Markdown
Contributor

Fixes #135191

CborReader now throws CborContentException when a root-level value sequence (AllowMultipleRootLevelValues) ends with a tag that is not followed by a data item, instead of reporting Finished. This applies to both single-buffer and incremental (SlideData) readers, so equivalent states now throw the same exception type.

Changes:

  • PeekStateCore: throw at the end of a root-level sequence if a tag is pending
  • PeekInitialByte: same check before the end-of-sequence guard, which covers the case where the tag is the only token consumed (SlideData rebases the offset to zero)
  • Updated PeekState_DanglingTagAtEndOfRootSequence, which asserted the old Finished behavior, and added a test for the tag-only case

Note: this changes shipped behavior. PeekState() previously returned Finished for a dangling root-level tag.

Testing: I verified the scenarios from the issue (before and after the change) with a scratch console project that compiles the library sources. I couldn't run the full System.Formats.Cbor test suite locally, so I'm relying on CI for that.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 7, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-formats-cbor, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@MuhammadBilal64

Copy link
Copy Markdown
Contributor Author

CI failed only on JSImportGenerator.Unit.Tests (windows-x86 CoreCLR_AllSubsets), exit code 0xC0000005 crash in an unrelated project. All System.Formats.Cbor tests passed. Could someone rerun the failed job? Thanks!

@bartonjs
bartonjs merged commit df38289 into dotnet:main Oct 12, 2026
86 of 88 checks passed
eiriktsarpalis added a commit that referenced this pull request Oct 14, 2026
…135621)

<!-- -->

Reserved additional-information values 28-30 are malformed CBOR, but
`ReadSimpleValue` reports their initial bytes (`0xFC`, `0xFD`, `0xFE`)
as `InvalidOperationException`. The same exception escapes through the
skip and encoded-value APIs. These inputs now throw
`CborContentException`, including when conformance checks are disabled.

The check is confined to the existing error branch. Valid floating-point
encodings and container-end misuse retain `InvalidOperationException`.
Regression coverage includes nested values, incremental input, all
conformance modes, and reader rollback. This is independent of the
dangling-tag fix in
[#135359](#135359), with no
changed-file overlap.

`ReadUnixTimeSeconds` now translates both `ArgumentOutOfRangeException`
and `OverflowException` from numerical conversion to
`InvalidOperationException` when the encoded Unix time cannot be
represented by `DateTimeOffset`. The original exception is preserved as
the inner cause, and failures restore the reader checkpoint. The
numerical operations are unchanged, with no success-path preflight
checks. Tests cover numeric boundaries and recovery, including strict
map-key validation. `ReadDecimal` retains its existing
`OverflowException` behavior; well-formed out-of-range values are not
reclassified as malformed CBOR.

> [!NOTE]
> This pull request was prepared with GitHub Copilot.

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d9a0557-8d2c-459a-9c86-4f143c98b2a4
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Formats.Cbor community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CborReader with AllowMultipleRootLevelValues reports Finished for a root sequence ending in a dangling tag

3 participants