Skip to content

Fix CborReader exception handling for reserved simple-value headers - #135621

Merged
eiriktsarpalis merged 6 commits into
dotnet:mainfrom
eiriktsarpalis:eiriktsarpalis-cbor-reader-reliability
Oct 14, 2026
Merged

eiriktsarpalis merged 6 commits into
dotnet:mainfrom
eiriktsarpalis:eiriktsarpalis-cbor-reader-reliability

Conversation

@eiriktsarpalis

@eiriktsarpalis eiriktsarpalis commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

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, 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.

Preserve numeric conversion exceptions and document Unix-time range failures. Add coverage for skip APIs, reader rollback, and numeric boundaries.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d9a0557-8d2c-459a-9c86-4f143c98b2a4
@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.

eiriktsarpalis and others added 2 commits October 13, 2026 05:55
Translate DateTimeOffset conversion argument exceptions on the error path, preserving reader rollback and existing numeric overflow behavior. Cover single-precision overflow and strict map-key recovery.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d9a0557-8d2c-459a-9c86-4f143c98b2a4
Translate both date-time argument range failures and numeric overflows in ReadUnixTimeSeconds as requested in review. Preserve the original exception as the inner cause, restore reader state, and keep validation off successful conversion paths.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d9a0557-8d2c-459a-9c86-4f143c98b2a4
eiriktsarpalis and others added 3 commits October 13, 2026 14:14
Replace the catch-all exception type test with separate ArgumentOutOfRangeException and OverflowException catch clauses, preserving reader rollback and InvalidOperationException wrapping.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d9a0557-8d2c-459a-9c86-4f143c98b2a4
Use an or pattern in the exception filter to share rollback and InvalidOperationException translation for argument range failures and numeric overflow.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d9a0557-8d2c-459a-9c86-4f143c98b2a4
Restore the shared catch handler with an exception type check, preserving checkpoint rollback and InvalidOperationException translation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d9a0557-8d2c-459a-9c86-4f143c98b2a4
@eiriktsarpalis
eiriktsarpalis merged commit cad3a82 into dotnet:main Oct 14, 2026
86 of 88 checks passed
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.

2 participants