Skip to content

[6.1] Preserve sequential Unicode source buffers (#4945) - #4963

Merged
cheenamalhotra merged 1 commit into
release/6.1from
dev/cheena/automation/backport-4945-6-1
Nov 3, 2026
Merged

cheenamalhotra merged 1 commit into
release/6.1from
dev/cheena/automation/backport-4945-6-1

Conversation

@cheenamalhotra

Copy link
Copy Markdown
Member

Description

Backport #4945 (source commit 8dae63509ca17fa5b345596f7f3752bea7a4defd) to release/6.1.

Sequential nvarchar reads could corrupt text on big-endian platforms because the decoder byte-swapped the caller's source buffer, including bytes not consumed by a capacity-limited conversion. Decode UTF-16LE directly into the destination instead, preserving raw code units, offsets, partial reads, zero-capacity behavior, and source ownership. The production decoder change matches the merged fix.

Release-specific adaptations:

  • Both .NET Framework and .NET projects link the same decoder source; one implementation change covers both.
  • Retain 6.1's net8.0, net9.0, and net462 targets and existing dependencies. No project restructuring, package updates, or public API changes.
  • Add the Unicode SQL regression explicitly to the manual test project's TestSet=3 compile list. This branch does not have main's globalization test file or DatabaseObjects fixtures, so use a connection-scoped temporary table, created by a separate unparameterized command to preserve its session scope.
  • Add release-specific TESTGUIDE.md; omit unrelated UTF-8 globalization coverage.

Issues

Backports #4945.

Remote release/6.1 was fetched before implementation and again before publication; it remains at b133d8a7defa7919125e961638c5ac5b256f187c. No existing matching backport or conflicting fix was found.

Testing

Windows x64: 33 decoder unit cases and 12 SQL round-trip cases passed, with zero skips on the final runs. SQL integration used existing SQL LocalDB 17.0.4025.3 with native SNI and the master database; only connection-scoped temporary tables were created. Coverage includes raw UTF-16LE/unpaired surrogates, immutable input, offsets, partial consumption, odd trailing bytes, zero capacity, buffered/streamed parameters, synchronous/asynchronous readers, packet-spanning values, read sizes 1/3/mixed, sentinels, and repeatable EOF.

The repository-pinned SDK 9.0.312 was unavailable. Commands were executed from the session directory against absolute project paths using installed SDK 10.0.403 without modifying global.json. -p:NuGetAudit=false bypassed an inaccessible vulnerability-data feed that otherwise caused NU1900-as-error; dependency versions and feeds were unchanged.

Exact successful commands and results:

Set-Location 'C:\Users\cmalhotra\.copilot\session-state\791bf66c-2de8-4144-85e2-70c162a9fcd2'

dotnet test 'D:\copilot\copilot-worktrees\SqlClient\dev-cheena-laughing-spork\src\Microsoft.Data.SqlClient\tests\UnitTests\Microsoft.Data.SqlClient.UnitTests.csproj' --framework net8.0 --filter "FullyQualifiedName~SqlUnicodeEncodingTests" --blame-hang-timeout 10m --verbosity quiet -p:NuGetAudit=false
# Passed: 11; failed: 0; skipped: 0.
dotnet test 'D:\copilot\copilot-worktrees\SqlClient\dev-cheena-laughing-spork\src\Microsoft.Data.SqlClient\tests\UnitTests\Microsoft.Data.SqlClient.UnitTests.csproj' --framework net9.0 --filter "FullyQualifiedName~SqlUnicodeEncodingTests" --blame-hang-timeout 10m --verbosity quiet -p:NuGetAudit=false
# Passed: 11; failed: 0; skipped: 0.
dotnet test 'D:\copilot\copilot-worktrees\SqlClient\dev-cheena-laughing-spork\src\Microsoft.Data.SqlClient\tests\UnitTests\Microsoft.Data.SqlClient.UnitTests.csproj' --framework net462 --filter "FullyQualifiedName~SqlUnicodeEncodingTests" --blame-hang-timeout 10m --verbosity quiet -p:NuGetAudit=false
# Passed: 11; failed: 0; skipped: 0.

dotnet test 'D:\copilot\copilot-worktrees\SqlClient\dev-cheena-laughing-spork\src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj' --framework net8.0 -p:TestSet=3 --filter "FullyQualifiedName~UnicodeParameterAndReaderRoundTrip_PreservesWorldwideText" --blame-hang-timeout 10m --verbosity quiet -p:NuGetAudit=false
# Passed: 4; failed: 0; skipped: 0.
dotnet build 'D:\copilot\copilot-worktrees\SqlClient\dev-cheena-laughing-spork\src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj' --framework net9.0 -p:TestSet=3 -p:NuGetAudit=false --verbosity quiet
# Passed: 0 warnings, 0 errors.
dotnet build 'D:\copilot\copilot-worktrees\SqlClient\dev-cheena-laughing-spork\src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj' --framework net462 -p:TestSet=3 -p:NuGetAudit=false --verbosity quiet
# Passed: 0 warnings, 0 errors.
dotnet test 'D:\copilot\copilot-worktrees\SqlClient\dev-cheena-laughing-spork\src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj' --framework net9.0 -p:TestSet=3 --no-build --filter "FullyQualifiedName~UnicodeParameterAndReaderRoundTrip_PreservesWorldwideText" --blame-hang-timeout 10m --verbosity quiet -p:NuGetAudit=false
# Passed: 4; failed: 0; skipped: 0.
dotnet test 'D:\copilot\copilot-worktrees\SqlClient\dev-cheena-laughing-spork\src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj' --framework net462 -p:TestSet=3 --no-build --filter "FullyQualifiedName~UnicodeParameterAndReaderRoundTrip_PreservesWorldwideText" --blame-hang-timeout 10m --verbosity quiet -p:NuGetAudit=false
# Passed: 4; failed: 0; skipped: 0.

Temporary output-directory config.json overrides supplied LocalDB connection strings for TCP/NP configuration fields. For net8/net9, the existing pinned SNI runtime 6.0.3 win-x64 DLL was copied from the restored package into test output; net462 already had the required architecture DLLs. Overrides were deleted after validation. Initial unconfigured/skipped and missing-native-DLL runs were not counted as passes; all four SQL cases executed on each final run.

git diff --check and git diff HEAD^ HEAD --check: passed. No source changes have been made since validation.

Outstanding validation: x64 runs exercise only the little-endian decoder path. The big-endian branch still requires a real big-endian client runtime (for example s390x); these results do not claim big-endian execution. The original customer platform/repro was not available. Full suites were not run.

  • Tests added or updated
  • Public API changes documented (not applicable; no public API changes)
  • Verified against customer repro (real big-endian client unavailable)
  • Ensure no breaking changes introduced

Guidelines

Please review the contribution guidelines before submitting a pull request:

Backport #4945 from commit 8dae635.

Keep the shared decoder fix and ownership/boundary tests. Adapt SQL Unicode regression coverage to the 6.1 explicit test includes, net8.0/net9.0/net462 targets, and connection-scoped temporary tables; omit unrelated UTF-8 coverage and main-only fixtures.

Validated 11 decoder cases and 4 LocalDB round-trip cases per framework on Windows x64. Real big-endian execution remains required.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 20:07
@cheenamalhotra
cheenamalhotra requested a review from a team as a code owner November 2, 2026 20:07
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Nov 2, 2026
@cheenamalhotra cheenamalhotra added this to the 6.1.9 milestone Nov 2, 2026

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.

🔵 Needs a closer look

Reported validation covers only little-endian x64, leaving the corrected big-endian decoding path untested on its target runtime and requiring maintainer review of release risk.

No open issues 🎉

What changed in this PR

Backports #4945 to release/6.1 to fix corrupted sequential nvarchar reads on big-endian platforms. The shared decoder now reads UTF-16LE directly into the destination without modifying the source buffer.

Changes:

  • Preserves raw code units, offsets, and partial-read behavior without public API or dependency changes.
  • Adds decoder unit tests and SQL round-trip tests, registered in manual test set 3.
  • Documents release-specific test commands and the requirement for real big-endian validation.

Reported x64 validation passed across all three target frameworks; the big-endian path remains unvalidated.

File Description
TESTGUIDE.md Documents regression commands and platform validation limits.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​SqlUnicodeEncodingTests.cs Tests source preservation, code units, offsets, and capacity boundaries.
src/​Microsoft.Data.SqlClient/​tests/​ManualTests/​SQL/​GlobalizationTest/​GlobalizationEncodingTests.cs Tests Unicode SQL round trips with buffered and streamed input and synchronous/asynchronous reads.
src/​Microsoft.Data.SqlClient/​tests/​ManualTests/​Microsoft.Data.SqlClient.ManualTesting.Tests.csproj Includes the regression in manual test set 3.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlSequentialTextReader.cs Replaces source-buffer byte swapping with non-mutating decoding.

Review effort: Balanced

@cheenamalhotra
cheenamalhotra merged commit 13aa5a0 into release/6.1 Nov 3, 2026
279 checks passed
@cheenamalhotra
cheenamalhotra deleted the dev/cheena/automation/backport-4945-6-1 branch November 3, 2026 17:18
@github-project-automation github-project-automation Bot moved this from To triage to Done in SqlClient Board Nov 3, 2026
@mdaigle mdaigle mentioned this pull request Nov 16, 2026
3 of 4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants