Skip to content

[6.1.9 Cherry-pick] Parser: Reject negative legacy (non-PLP) value lengths - #5185

Draft
github-actions[bot] wants to merge 2 commits into
release/6.1from
dev/automation/pr-5163-to-6.1.9
Draft

github-actions[bot] wants to merge 2 commits into
release/6.1from
dev/automation/pr-5163-to-6.1.9

Conversation

@github-actions

@github-actions github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Cherry-pick of #5163 (ec42969) into release/6.1.

The merged #5163 rejects malformed negative legacy (non-PLP image/text/ntext) value lengths as corrupted TDS data, instead of treating them as empty values and leaving bytes unconsumed. Valid values keep their existing exact-size allocation.

Conflict resolution

release/6.1 has separate netcore and netfx TdsParser copies and doesn't have TdsParserStateObject.TryReadByteArrayWithContinue.

  • TryGetDataLength: applied the intLength < 0 check to both netcore/src/.../Parser/TdsParser.cs and netfx/src/.../Parser/TdsParser.cs. Kept 6.1's shared TdsParser.cs unchanged.
  • TdsParserStateObject.cs: kept 6.1's code. Instead of adding TryReadByteArrayWithContinue, added the same !isPlp && length < 0 guard to 6.1's non-PLP TryReadStringWithEncoding path.
  • TESTGUIDE.md: 6.1's guide is release-specific, so it was kept and a short section was added for these tests.

Test adaptation

  • TdsParserStateObjectTests: the negative-length helper test now targets TryReadStringWithEncoding. The exact-size helper test was dropped, because 6.1's allocation path wasn't changed.
  • SqlDataReaderTests:
    • removed the UseCompatibilityProcessSni/UseCompatibilityAsyncBehaviour scopes, which aren't on 6.1, whose async behavior is the legacy mode;
    • dropped ReadAsync_FragmentedLegacyLob_ResumesValue, which needs snapshot "continue" support 6.1 doesn't have;
    • kept all other value, async, streaming, cancellation and negative-length tests.
  • Added #nullable enable to the new test files, because 6.1's unit tests have no nullable context.

Testing

  • dotnet build build.proj -t:BuildNetCore — passed.
  • dotnet build src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj -p:OSGroup=Windows_NT — passed. This compiles netfx; netfx tests were not run on Linux.
  • dotnet test src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj -p:TestTargetOS=Unixnetcoreapp --filter "(FullyQualifiedName~UnitTests.SqlDataReaderTests|FullyQualifiedName~UnitTests.TdsParserStateObjectTests)&category!=failing&category!=flaky" — passed, 48/48 on net8.0 and net9.0. Without the product change, the 3 negative-length tests failed (sync, async and helper).
  • Full unit suite, net8.0 (category!=failing&category!=flaky&category!=interactive) — 695 passed, 1 failed. The failure, ConnectionFailoverTests.TransientFault_IgnoreServerProvidedFailoverPartner_ShouldConnectToUserProvidedPartner, also fails on unmodified release/6.1 in the same environment.

To resolve, run:  git cherry-pick ec42969
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Reject malformed negative legacy (non-PLP) value lengths as corrupted TDS data instead of treating them as empty values. Valid values keep the existing exact-size allocation; zero-length and PLP values are unchanged.

[6.1] Applied the TryGetDataLength check to the separate netcore and netfx TdsParser copies, and the non-PLP guard to TryReadStringWithEncoding (release/6.1 has no TryReadByteArrayWithContinue). Tests: retargeted the helper-level negative test to TryReadStringWithEncoding, dropped the exact-size helper test and the snapshot-continuation test (no continue mode on 6.1), removed compatibility-switch scopes, and enabled nullable context in the new test files. Kept 6.1's release-specific TESTGUIDE and added a section for these tests.

(cherry picked from commit ec42969)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@paulmedynski paulmedynski changed the title [6.1.9 Cherry-pick - CONFLICTS] Parser: Grow non-PLP value buffers as payload arrives [6.1.9 Cherry-pick] Parser: Grow non-PLP value buffers as payload arrives Dec 4, 2026
@paulmedynski paulmedynski changed the title [6.1.9 Cherry-pick] Parser: Grow non-PLP value buffers as payload arrives [6.1.9 Cherry-pick] Parser: Reject negative legacy (non-PLP) value lengths Dec 4, 2026

This branch has not been deployed

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

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

1 participant