[S.T.J] Fix PropertyRef.Equals - #133027
Merged
Merged
Conversation
…so > PropertyNameKeyLength
|
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. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-text-json |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Pull request overview
Fixes an equality bug in System.Text.Json’s UTF-8 property-name cache where a short property name (≤7 bytes) could incorrectly match a cached long property name that happens to share the same embedded key (due to the key encoding truncating length to one byte).
Changes:
- Update
PropertyRef.Equals(ReadOnlySpan<byte>, ulong)to only skip full byte comparison when both property names fit in the embedded-key format (≤7 bytes). - Add a regression test that constructs two names with the same computed key but different lengths and verifies they remain distinct in the property cache.
File summaries
| File | Description |
|---|---|
| src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/PropertyRef.cs | Tightens equality logic to avoid false positives when key collisions occur between short and long UTF-8 names. |
| src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/CacheTests.cs | Adds coverage for the key-collision scenario to prevent regressions in property cache lookups. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
eiriktsarpalis
approved these changes
Sep 1, 2026
PranavSenthilnathan
approved these changes
Sep 1, 2026
Member
Author
|
/backport to release/11.0 |
Contributor
|
Started backporting to |
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to |
Member
Author
|
/backport to release/9.0-staging |
Contributor
|
Started backporting to |
This was referenced Sep 2, 2026
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.
To compare name if
this.Utf8PropertyNameis also >PropertyNameKeyLength.