Repository navigation
Fix handling of non-ASCII data in indefinite strings - #131235
Conversation
|
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. |
|
Tagging subscribers to this area: @dotnet/area-system-formats-cbor, @bartonjs, @vcsjones |
There was a problem hiding this comment.
Pull request overview
This PR fixes CborReader.TryReadTextString for indefinite-length, concatenated text strings containing non-ASCII UTF-8 data by advancing the destination span by the actual number of chars written per chunk (rather than the chunk’s byte length). This brings the TryRead* behavior in line with ReadTextString for multi-byte UTF-8 sequences.
Changes:
- Fix span-advancement logic in
TryReadIndefiniteLengthTextStringConcatenatedto slice bychunkCharsWritteninstead of the chunk byte length. - Extend text-string test vectors to include additional non-ASCII cases (Latin-1, German umlaut, Cyrillic) for both definite and indefinite-length concatenated strings.
- Add/expand tests to validate
TryReadTextStringparity withReadTextStringfor several error/edge cases (non-canonical lengths, invalid data, size-too-large, empty input, invalid UTF-8 chunking).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Formats.Cbor/tests/Reader/CborReaderTests.TextString.cs | Adds broader non-ASCII and indefinite-length concatenation coverage; extends parity checks for TryReadTextString across existing scenarios. |
| src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs | Correctly advances the destination span by the number of decoded chars per UTF-8 chunk when concatenating indefinite-length text strings. |
|
/backport to release/9.0-staging |
|
Started backporting to |
|
/backport to release/8.0-staging |
|
Started backporting to |
|
/backport to release/10.0 |
|
Started backporting to |
|
@bartonjs backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix handling of non-ASCII data in indefinite strings
Using index info to reconstruct a base tree...
M src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs
CONFLICT (content): Merge conflict in src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix handling of non-ASCII data in indefinite strings
Error: The process '/usr/bin/git' failed with exit code 128 |
|
@bartonjs backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix handling of non-ASCII data in indefinite strings
Using index info to reconstruct a base tree...
M src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs
M src/libraries/System.Formats.Cbor/tests/Reader/CborReaderTests.TextString.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs
CONFLICT (content): Merge conflict in src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs
Auto-merging src/libraries/System.Formats.Cbor/tests/Reader/CborReaderTests.TextString.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix handling of non-ASCII data in indefinite strings
Error: The process '/usr/bin/git' failed with exit code 128 |
|
@bartonjs backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix handling of non-ASCII data in indefinite strings
Using index info to reconstruct a base tree...
M src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs
CONFLICT (content): Merge conflict in src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix handling of non-ASCII data in indefinite strings
Error: The process '/usr/bin/git' failed with exit code 128 |
…ngs (#131278) Backport of #131235 to release/10.0 ## Customer Impact - [x] Customer reported - [ ] Found internally When reading an indefinite-length encoded text string, TryReadTextString moves the write position forward the number of bytes read, not the number of chars written, so non-ASCII data gets exceptions that a precisely-sized buffer is too small (despite having had the size pre-validated). ## Regression - [ ] Yes - [x] No It seems to have had this behavior since the method was introduced, in .NET 5. ## Testing This change includes tests that exercise the pattern better, including having a non-ASCII character in something other than the final position in a string. ## Risk Low. Existing test coverage shows no regressions for pure-ASCII and Unicode-final-only, new test coverage shows Unicode-before-final works correctly. ## Package authoring no longer needed in .NET 9 **IMPORTANT**: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version. Keep in mind that we still need package authoring in .NET 8 and older versions.
No description provided.