-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Fix buffer slicing in (U)Int128 property name serialization #116868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: PranavSenthilnathan <[email protected]>
Co-authored-by: PranavSenthilnathan <[email protected]>
|
||
// Should not contain null characters or other garbage data | ||
Assert.DoesNotContain('\0', json); | ||
Assert.DoesNotContain('\uFFFD', json); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot this is junk data specific to the shared reproduction, so we don't need check that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the junk data checks as requested (debf1a4).
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.WriteTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.WriteTests.cs
Outdated
Show resolved
Hide resolved
…ecks Co-authored-by: PranavSenthilnathan <[email protected]>
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.WriteTests.cs
Show resolved
Hide resolved
Co-authored-by: PranavSenthilnathan <[email protected]>
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.WriteTests.cs
Outdated
Show resolved
Hide resolved
…rialization/Value.WriteTests.cs
…ionary test Co-authored-by: eiriktsarpalis <[email protected]>
|
||
string json = JsonSerializer.Serialize(dict); | ||
|
||
// E2E validation: should roundtrip correctly without any junk data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has removed any assertions on the resultant json
altogether. Please introduce an Assert.Equals
checking json
against an expected value. Do the same for the second test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added JSON content validation with Assert.Contains checks for expected keys and DoesNotContain check for junk data. Both tests now validate the JSON content before roundtrip testing (f40d227).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do NOT use Assert.Contains
. Only use Assert.Equals
validating the E2E json value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced Assert.Contains with Assert.Equal for E2E JSON validation. Updated tests to use single-element dictionaries ensuring deterministic output for reliable validation (1360919).
…nt validation Co-authored-by: eiriktsarpalis <[email protected]>
…Int128/UInt128 tests Co-authored-by: eiriktsarpalis <[email protected]>
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.WriteTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: eiriktsarpalis <[email protected]>
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.WriteTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: eiriktsarpalis <[email protected]>
src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.WriteTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: eiriktsarpalis <[email protected]>
Fixes a bug where
Int128Converter
andUInt128Converter
were writing unsliced buffers when serializing as property names, causing garbage data to appear in JSON output.Problem
When using
Int128
orUInt128
as dictionary keys, the JSON serialization would produce malformed output with garbage characters:Root Cause
Both
Int128Converter.WriteAsPropertyNameCore
andUInt128Converter.WriteAsPropertyNameCore
were passing the entire unslicedstackalloc
buffer towriter.WritePropertyName(buffer)
instead of slicing it to the actual written length.Fix
Updated both converters to slice the buffer correctly:
This aligns with the existing pattern used in
WriteCore
andWriteNumberWithCustomHandling
methods in the same files.Testing
Int128
andUInt128
typesFixes #116855.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.