Repository navigation
Conversation
Use the connection encoding to count transmitted ANSI bytes before selecting MAX metadata. This prevents UTF-8 values below 8000 characters but above 8000 bytes from producing invalid VARCHAR declarations and RPC framing. Cover encoded byte boundaries, inferred sizes, truncation, offsets and SqlString values with unit regressions. Add SQL Server round-trip tests for text, stored procedure and prepared commands with sync and async execution. Validation: 1502 unit tests and 206 parameter functional tests passed; the Windows-only integrated authentication test was excluded on Linux. All 19 wire scenarios passed, including replay of the original EF command. Driver builds passed for net10.0 and net462. Live SQL Server tests compile but remain unverified locally. Fixes dotnet#2035
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
@dotnet-policy-service agree |
priyankatiwari08
left a comment
There was a problem hiding this comment.
Fix mirrors the serializer's byte-count logic correctly, but the rollout is incomplete.
SqlParameter.MetaDataForSmi(SqlParameter.cs:1741) still callsValidateTypeLengths()with no parser, so the Always Encryptedtype_infopath keeps the old character-based promotion and can disagree with the RPC metadata for the same parameter.- No test covers Always Encrypted or
Offset-with-unset-Sizefor the new path.
| // func will change type to that with a 4 byte length if the type has a two | ||
| // byte length and a parameter length > than that expressible in 2 bytes | ||
| internal MetaType ValidateTypeLengths() | ||
| internal MetaType ValidateTypeLengths(TdsParser parser = null) |
There was a problem hiding this comment.
Defaulting parser to null silently preserves the old character-based behaviour at any call site that misses it — and one already does (MetaDataForSmi, line 1741). Make it a required argument so the compiler flags every caller.
| object value = GetCoercedValue(); | ||
| string text = value is SqlString sqlString ? sqlString.Value : | ||
| value is SqlChars sqlChars ? new string(sqlChars.Value) : (string)value; | ||
| actualSizeInBytes = parser.GetEncodingCharLength(text, (int)actualSizeInBytes, Offset, null); |
There was a problem hiding this comment.
GetActualSize() returns min(Size, value.Length), not value.Length - Offset, so with a non-zero Offset and unset Size this resolves to GetByteCount(text, Offset, text.Length) and throws ArgumentOutOfRangeException. Clamp numChars to text.Length - Offset.
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #4824 +/- ##
==========================================
- Coverage 72.43% 66.08% -6.35%
==========================================
Files 292 289 -3
Lines 45471 68690 +23219
==========================================
+ Hits 32937 45394 +12457
- Misses 12534 23296 +10762
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@jtheisen This pull request has been marked as Author attention needed. When you have addressed the reviewer feedback and are ready for another review, please post a comment with |
AI Disclaimer
I'm the original reporter of this issue and the test case 3 years ago. AI (Codex/6.1-Sol) now helped me create this PR which apparently fixes this issue, but I can't say that I properly understand it. However, I thought it could be at least a helpful starting point.
Description
ANSI parameter metadata can be invalid when a value fits within 8,000 characters but exceeds 8,000 bytes in the connection encoding. For example, 4,001
écharacters occupy 8,002 UTF-8 bytes. The driver currently selects non-MAX metadata using the character count, causing SQL Server to reject the RPC with an invalid data length or metadata length error.This change counts transmitted ANSI bytes using the connection’s negotiated encoding before selecting MAX metadata. The calculation respects parameter size and offset. Public APIs and the character-based semantics of
SqlParameter.Sizeremain unchanged.Adds unit regression coverage and SQL Server round-trip tests. Database tests use unique database names and clean up their resources.
Issues
Fixes #2035.
Testing
SqlStringvalues.Both comparison workflows report success when their expected outcomes are verified; the baseline’s green status means the expected failures were confirmed.
Additional local validation:
net10.0andnet462.The fork-specific comparison workflows are separate from this PR. Windows runtime validation remains for upstream CI.