Skip to content

Fix bounds checks in NativeFormat integer decoders - #137908

Merged
MichalStrehovsky merged 2 commits into
mainfrom
fix-nativeformat-decoder-bounds
Nov 20, 2026
Merged

MichalStrehovsky merged 2 commits into
mainfrom
fix-nativeformat-decoder-bounds

Conversation

@MichalStrehovsky

@MichalStrehovsky MichalStrehovsky commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

The bounded NativePrimitiveDecoder methods validate the shorter integer encodings but read the full-width payloads without checking streamEnd. A truncated five-byte or nine-byte encoding can therefore read beyond the supplied buffer.

Check the entire payload before advancing the cursor or reading it in DecodeUnsigned, DecodeSigned, DecodeUnsignedLong, and DecodeSignedLong. This fixes the shared decoder rather than requiring caller-side validation, as discussed in this review comment.

The change is limited to the four missing bounds checks. Existing assertion behavior is preserved, and no test changes are included.

Validation

Before removing the test changes, a Release regression run passed all 18 cases, covering truncated and exact-length payloads. Without the bounds checks, all 12 nonempty truncated-input cases failed because no exception was thrown.

After removing the test changes, ILCompiler.TypeSystem.Tests built successfully in Release. A Debug build of ILCompiler.MetadataTransform was blocked during restore because the NuGet vulnerability-data endpoint was unavailable (NU1900 / NU1905).

No full runtime build or full test suite was run.

Note

This pull request was prepared with GitHub Copilot.

Check full-width payloads before reading bounded integer encodings.\nCover truncated and exact-length payloads in the compiler unit tests,\nand let invalid input throw in Debug builds instead of asserting.

Co-authored-by: Copilot <[email protected]>
@azure-pipelines

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

Keep only the four missing decoder bounds checks and preserve the existing debug assertion behavior.

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 19, 2026
@jkotas jkotas added area-NativeAOT-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 19, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the bounds-check additions to the four full-width integer decoding paths.

No open issues 🎉

What changed in this PR

This PR closes four missing bounds checks in the shared NativeFormat integer decoder, preventing truncated full-width encodings from reading beyond the supplied buffer.

Changes:

  • Validate five-byte encodings in DecodeUnsigned and DecodeSigned.
  • Validate nine-byte encodings in DecodeUnsignedLong and DecodeSignedLong.
  • Perform checks before advancing the cursor or reading payloads, preserving existing assertion behavior. No tests are added.
File Description
src/​coreclr/​tools/​Common/​Internal/​NativeFormat/​NativeFormatReader.cs Adds bounds checks to the four full-width integer decoding paths.

Review effort: Balanced

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/ba-g macos machine infra issues

@MichalStrehovsky
MichalStrehovsky enabled auto-merge (squash) November 20, 2026 04:31
@MichalStrehovsky
MichalStrehovsky merged commit 421c9dd into main Nov 20, 2026
109 of 112 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the fix-nativeformat-decoder-bounds branch November 20, 2026 04:31
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 23, 2026
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.

3 participants