Repository navigation
Fix bounds checks in NativeFormat integer decoders - #137908
Merged
Merged
Conversation
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: 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]>
jkotas
approved these changes
Nov 19, 2026
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
Contributor
There was a problem hiding this comment.
🟢 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
DecodeUnsignedandDecodeSigned. - Validate nine-byte encodings in
DecodeUnsignedLongandDecodeSignedLong. - 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
This was referenced Nov 19, 2026
Member
Author
|
/ba-g macos machine infra issues |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The bounded
NativePrimitiveDecodermethods validate the shorter integer encodings but read the full-width payloads without checkingstreamEnd. 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, andDecodeSignedLong. 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.Testsbuilt successfully in Release. A Debug build ofILCompiler.MetadataTransformwas 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.