Repository navigation
fix: resolve a Binary length of 0 or NaN from the value - #1817
arthurschreiber merged 10 commits into
Conversation
Since tediousjs#1774, an explicit Binary length of 0 or NaN was sent as a zero TYPE_INFO length while the declaration still said binary(n), so the server rejected the request. Treat a falsy length as unspecified, as Binary did before 20.3.0 and as its declaration does. Fixes tediousjs#1812 Co-authored-by: Copilot App <[email protected]>
An empty Binary value now declares binary(1) instead of a zero length, which the server rejects. A declared length larger than the value now writes the value's actual byte count, so the stream is not corrupted; the server pads the value. Both match Microsoft.Data.SqlClient's wire format. Co-authored-by: Copilot App <[email protected]>
Covers tediousjs#1812 (a length of 0 or NaN), padding, truncation and an empty value. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1817 +/- ##
==========================================
- Coverage 84.76% 83.88% -0.89%
==========================================
Files 96 96
Lines 4720 4728 +8
Branches 884 888 +4
==========================================
- Hits 4001 3966 -35
- Misses 455 509 +54
+ Partials 264 253 -11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ry-explicit-length
…ry-explicit-length
|
Thanks @cheenamalhotra, this is a good find. I'm happy with the direction: treating a For context, I ran the same cases against SQL Server 2025 with tedious 14.7.0 through 20.3.5 and with this branch, covering request parameters, bulk load and TVPs:
Must fix:
|
Co-authored-by: Copilot App <[email protected]>
Addressed in bf6595d: parameter truncation happens in The current HEAD passes the SQL Server CI matrix, including the integration tests. Local targeted regressions, lint and build also pass. |
|
🎉 This PR is included in version 20.3.9 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Since 20.3.0, a
Binaryparameter with an explicitlength: 0orNaNis rejected by the server (#1812).Fixes #1812
Cause
#1774 moved length resolution into
resolveParameter(), which keeps any explicit length (!= null), including0. Before, a falsy length fell back toresolveLength().Binary.resolveLength()ignoresparameter.length, soBinarywas the one type whose wire bytes changed: TYPE_INFO said length 0 whiledeclaration()(still truthiness-based) saidbinary(2).Changes
Binarygets a nativeresolve()that treats a falsy length as unspecified, restoring pre-20.3.0 parameter behavior. It reusesresolveLength(), which now infers 1 for an empty buffer rather than the invalid length 0.writeValue()sends the actual byte count and rejects values longer than the declared length, so bulk-load and TVP rows cannot silently lose data. Shorter values are padded by the server.writeValue()treats bothnullandundefinedlengths as unspecified (!= null).execSql(), extended to compare Buffers withdeepEqual, instead of maintaining a duplicate connection helper.Notes for review
binary(1); the server accepts this existing behavior. The inaccurate comment claiming all TYPE_INFO lengths match declarations has been removed.Binarytreatslength: 0as unset, whileVarBinary/NVarCharkeep an explicit 0. This is deliberate: it matchesBinary's own declaration, andNaNcurrently selects max/PLP for those types, so changing them would be a separate behavior change.Char/NCharissues remain out of scope, as discussed in review.Verification
0x4A50, length 4 returned0x4A500000, length 1 returned0x4A, and an empty value returned0x00. Those parameter semantics are preserved by the review fixes.npm run lint(including TypeScript checking) andnpm run buildpass.mssql:1433does not resolve locally (ENOTFOUND). The new integration cases require CI verification.cc @saurabh500 @David-Engel @arthurschreiber