Skip to content

Commit 43220cd

Browse files
vkuttypCopilot
andcommitted
fix: correct EnvChange string-type detection in TdsDecoder
Types 5,6 are DWORD pairs (binary), not Unicode strings. Type 9 (commit tx), 12 (defect tx) are binary transaction descriptors. Types 19,20 are routing/reserved binary data. Only types 1-4 (database/language/charset/packetsize) and 13 (log shipping), 18 (user instance) use B_VARCHAR format. This caused EndOfStreamException during BeginTransaction_CommitAsync because COMMIT (type 9) has an 8-byte binary old-value but the code tried to read 16 bytes (8 × 2) as UTF-16. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 73375ae commit 43220cd

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/SqlDotnetty.MsSql/Tds/TdsDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private static TdsEnvChange ReadEnvChange(BinaryReader r)
237237
// String-value ENVCHANGE types: 1-6, 9, 12, 13, 19, 20.
238238
// Each has: newLen(1 byte = #Unicode chars) + newValue + oldLen(1) + oldValue.
239239
// Binary types (7=collation, 8=begin tx, 10-11=commit/rollback, etc.) use byte arrays.
240-
bool isStringType = changeType is >= 1 and <= 6 or 9 or 12 or 13 or 19 or 20;
240+
bool isStringType = changeType is >= 1 and <= 4 or 13 or 18;
241241
if (!isStringType)
242242
{
243243
// Binary ENVCHANGE: newLen(1 byte) + newValue(newLen bytes) + ...

0 commit comments

Comments
 (0)