Repository navigation
Fix NullReferenceException and InvalidCastException in SystemClassWithMembersAndTypesRecord - #121409
Merged
adamsitnik merged 5 commits intoNov 20, 2025
Merged
Conversation
…hMembersAndTypesRecord Co-authored-by: stephentoub <[email protected]>
Copilot
AI
changed the title
[WIP] Fix NullReferenceException in NrbfDecoderFuzzer
Fix NullReferenceException and InvalidCastException in SystemClassWithMembersAndTypesRecord
Nov 6, 2025
stephentoub
marked this pull request as ready for review
November 6, 2025 16:22
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes two security vulnerabilities found by fuzzing in the NRBF decoder when handling malformed DateTime serialization data. The fix adds proper validation to prevent InvalidCastException and NullReferenceException when processing member type information.
- Adds defensive checks to validate
BinaryTypeandAdditionalInfobefore casting in theHasMemberhelper method - Adds regression tests for both fuzzer-discovered edge cases
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/SystemClassWithMembersAndTypesRecord.cs | Adds validation to HasMember method to check BinaryType is Primitive and AdditionalInfo is not null before casting |
| src/libraries/System.Formats.Nrbf/tests/InvalidInputTests.cs | Adds two test cases for fuzzer-discovered bugs: one for incorrect BinaryType.SystemClass and one for null AdditionalInfo |
This was referenced Nov 6, 2025
Open
Co-authored-by: stephentoub <[email protected]>
adamsitnik
reviewed
Nov 7, 2025
adamsitnik
left a comment
Member
There was a problem hiding this comment.
@copilot please take a look at my comments.
Co-authored-by: adamsitnik <[email protected]>
stephentoub
reviewed
Nov 7, 2025
adamsitnik
approved these changes
Nov 20, 2025
adamsitnik
left a comment
Member
There was a problem hiding this comment.
@adamsitnik, just fyi, I copied these tests locally without the fix and verified they both fail.
@stephentoub big thanks for doing that, it was exactly what I needed to get convinced.
LGTM! ![]()
adamsitnik
deleted the
copilot/fix-nullreferenceexception-nrbf-decoder
branch
November 20, 2025 14:28
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fix NullReferenceException and InvalidCastException in SystemClassWithMembersAndTypesRecord
HasMemberlocal function inSystemClassWithMembersAndTypesRecord.DecodecastsAdditionalInfotoPrimitiveTypewithout checking if theBinaryTypeisPrimitiveBinaryTypeisSystemClass,AdditionalInfois aTypeName, not aPrimitiveType, causing NullReferenceException or InvalidCastExceptionHasMemberfunction to checkBinaryTypebefore castingOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.