Visitar URL original
[7.0.4] Validate TDS parser prerequisites and invalidate malformed responses (#4941) by github-actions[bot] · Pull Request #4982 · dotnet/SqlClient · GitHub
Skip to content

[7.0.4] Validate TDS parser prerequisites and invalidate malformed responses (#4941) - #4982

Merged
paulmedynski merged 2 commits into
release/7.0from
dev/automation/pr-4941-to-7.0.4
Nov 6, 2026
Merged

paulmedynski merged 2 commits into
release/7.0from
dev/automation/pr-4941-to-7.0.4

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Description

Cherry-pick of #4941 (b714187042261aa00efc0e7c8f421af3dfd9b4c4) into release/7.0 for 7.0.4, with merge conflicts resolved.

Validate the metadata and authentication prerequisites needed to consume ROW, NBCROW, ALTROW, and SSPI tokens. Malformed responses use the existing corrupted-stream parsing error and invalidate the connection instead of dereferencing missing state or using unrelated result metadata. Valid result processing remains unchanged.

Release-branch adaptations:

  • Preserve the release branch's alternate-metadata collection formatting while removing the obsolete debug assertion.
  • Include the upstream ConnectionPoolVersionScope and SimulatedServerPoolScope test helpers required by the regression tests.
  • Retain 44 applicable simulated-server cases, including synchronous/asynchronous rejection, pool recovery, valid results, and packet-boundary handling. Omit the four pool V2 cases because this branch explicitly throws NotImplementedException when that implementation is selected.
  • Register the new compatibility test in the manual-test project's explicit test-set-2 compile list, and use direct connection construction consistent with this branch because its DataTestUtility has no CreateConnection factory.

No public API declarations, dependencies, localized resources, connection-string settings, or AppContext switches change. Protocol rationale and malformed-response compatibility details are documented in #4941; no public documentation changes are required.

Issues

Backport of #4941.

@github-actions github-actions Bot added this to the 7.0.4 milestone Nov 3, 2026
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Nov 3, 2026
@azure-pipelines

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

@paulmedynski paulmedynski changed the title [7.0.4 Cherry-pick - CONFLICTS] Validate TDS parser prerequisites and invalidate malformed responses [7.0.4 Cherry-pick] Validate TDS parser prerequisites and invalidate malformed responses Nov 6, 2026
github-actions Bot and others added 2 commits November 6, 2026 06:47
To resolve, run:  git cherry-pick b714187
…4941)

* Validate parser prerequisites before consuming TDS tokens

Reject missing row metadata, unmatched alternate metadata, and unavailable SSPI providers through the existing corrupted-stream failure path. Guard reader transitions and add simulated-server and compatibility coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Explain parser regression test scenarios and assertions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Refactor parser prerequisite tests to address PR #4941 feedback

Separate reader/non-query, sync/async, and packet-boundary outcomes.
Share setup, pool recovery, and reader cleanup helpers while preserving
all 48 test cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit b714187)
@paulmedynski
paulmedynski force-pushed the dev/automation/pr-4941-to-7.0.4 branch from df7d816 to 58887b4 Compare November 6, 2026 10:47
@paulmedynski
paulmedynski requested a balanced review from Copilot November 6, 2026 10:48
@paulmedynski paulmedynski changed the title [7.0.4 Cherry-pick] Validate TDS parser prerequisites and invalidate malformed responses [7.0.4] Validate TDS parser prerequisites and invalidate malformed responses (#4941) Nov 6, 2026
@paulmedynski
paulmedynski marked this pull request as ready for review November 6, 2026 10:48
@paulmedynski
paulmedynski requested a review from a team as a code owner November 6, 2026 10:48
@paulmedynski

Copy link
Copy Markdown
Contributor

/azp run

@paulmedynski paulmedynski moved this from To triage to In review in SqlClient Board Nov 6, 2026
@paulmedynski paulmedynski added the Code Health 💊 Issues/PRs that are targeted to source code quality improvements. label Nov 6, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

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

Maintainer validation is needed because this backport affects connection teardown across login, async readers, and pooling, while real-server tests failed to connect and Windows/native-SNI and .NET Framework execution remain unverified.

No open issues 🎉

What changed in this PR

Backports #4941 to release/7.0 for 7.0.4, hardening SqlClient’s TDS parser against missing metadata or authentication state while preserving valid result processing.

Changes:

  • Validate ROW, NBCROW, ALTROW, and SSPI prerequisites; reject malformed responses with the existing corrupted-stream error and invalidate the connection.
  • Guard alternate-result transitions and remove the obsolete Debug-only metadata assertion.
  • Add 44 simulated-server regression cases, pool-isolation helpers, and four real-server compatibility cases adapted to the release branch.

Reported simulated-server tests passed across three target frameworks. Real-server runtime compatibility and Windows/.NET Framework validation remain unverified locally.

File Description
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​SimulatedServerTests/​ParserPrerequisiteTests.cs Tests malformed responses, pool recovery, valid results, and packet boundaries.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​SimulatedServerTests/​Fixtures/​SimulatedServerPoolScope.cs Isolates and clears each simulated-server scenario’s pool.
src/​Microsoft.Data.SqlClient/​tests/​ManualTests/​SQL/​ConnectivityTests/​ParserResultProcessingTest.cs Checks valid result processing and connection reuse with sync/async APIs.
src/​Microsoft.Data.SqlClient/​tests/​ManualTests/​Microsoft.Data.SqlClient.ManualTests.csproj Includes the compatibility test in test set 2.
src/​Microsoft.Data.SqlClient/​tests/​Common/​ConnectionPoolVersionScope.cs Scopes pool selection and clears pools before and after use.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlDataReader.cs Rejects missing or unmatched alternate-result metadata.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​Tokens/​TdsAltMetadataCollection.cs Removes the Debug-only failure for unmatched metadata identifiers.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​Parser/​TdsParser.cs Adds prerequisite checks and shared corrupted-stream rejection.

Review effort: Balanced

@paulmedynski
paulmedynski enabled auto-merge (squash) November 6, 2026 10:54
@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.79%. Comparing base (0620c4c) to head (58887b4).
⚠️ Report is 4 commits behind head on release/7.0.

Files with missing lines Patch % Lines
...t/src/Microsoft/Data/SqlClient/Parser/TdsParser.cs 84.00% 4 Missing ⚠️
...ient/src/Microsoft/Data/SqlClient/SqlDataReader.cs 63.63% 4 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (0620c4c) and HEAD (58887b4). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (0620c4c) HEAD (58887b4)
CI-SqlClient 1 0
Additional details and impacted files
@@               Coverage Diff               @@
##           release/7.0    #4982      +/-   ##
===============================================
- Coverage        73.21%   66.79%   -6.42%     
===============================================
  Files              296      291       -5     
  Lines            43453    66420   +22967     
===============================================
+ Hits             31813    44368   +12555     
- Misses           11640    22052   +10412     
Flag Coverage Δ
CI-SqlClient ?
PR-SqlClient-Project 66.79% <77.77%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@paulmedynski
paulmedynski merged commit 6c0cfdc into release/7.0 Nov 6, 2026
290 checks passed
@paulmedynski
paulmedynski deleted the dev/automation/pr-4941-to-7.0.4 branch November 6, 2026 16:19
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code Health 💊 Issues/PRs that are targeted to source code quality improvements.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants