Skip to content

[release/10.0] Fix handling of non-ASCII data in CBOR indefinite strings#131278

Open
bartonjs wants to merge 1 commit into
dotnet:release/10.0from
bartonjs:cbor_indef_nonascii_10
Open

[release/10.0] Fix handling of non-ASCII data in CBOR indefinite strings#131278
bartonjs wants to merge 1 commit into
dotnet:release/10.0from
bartonjs:cbor_indef_nonascii_10

Conversation

@bartonjs

@bartonjs bartonjs commented Jul 23, 2026

Copy link
Copy Markdown
Member

Backport of #131235 to release/10.0

Customer Impact

  • 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
  • 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.

@bartonjs bartonjs added this to the 10.0.x milestone Jul 23, 2026
@bartonjs bartonjs self-assigned this Jul 23, 2026
Copilot AI review requested due to automatic review settings July 23, 2026 17:21
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-formats-cbor, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes CborReader.TryReadTextString handling for indefinite-length text strings containing non-ASCII UTF-8, ensuring destination slicing advances by the number of chars written (not the UTF-8 byte length). This aligns TryRead... behavior with the existing ReadTextString() concatenation logic and improves correctness for multi-byte UTF-8 chunks.

Changes:

  • Fix TryReadIndefiniteLengthTextStringConcatenated to slice the destination span by chunkCharsWritten rather than the chunk’s byte length.
  • Add/extend unit test coverage for non-ASCII text (e.g., “São Paulo”, “München”, Cyrillic) across ReadTextString and TryReadTextString, including additional conformance/error-path coverage.

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 regression coverage for non-ASCII text and expands TryReadTextString coverage across success/failure paths.
src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Reader/CborReader.String.cs Fixes the span-advance logic when concatenating UTF-8 chunks for indefinite-length text strings in TryRead....

@bartonjs

Copy link
Copy Markdown
Member Author

/backport to release/9.0-staging

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/9.0-staging (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@bartonjs backporting to release/9.0-staging was not run because the source pull request has not been merged. Please merge this pull request before requesting a backport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants