prisma / tiberius

TDS 7.2+ (Microsoft SQL Server) driver for Rust
Apache License 2.0
311 stars 113 forks source link

Fix encoding of zero-length values for large varlen columns #315

Closed descawed closed 3 months ago

descawed commented 9 months ago

When encoding a value for a large varlen column (e.g. varchar(max), nvarchar(max), varbinary(max)), tiberius writes the value in a single chunk, then writes a zero length chunk to signal the end of the column data. However, if the value being encoded has length zero, the first chunk already ends the column data, and the server will incorrectly interpret the extra zero as part of the next column's data (or whatever follows this column in the buffer). This PR skips the terminating zero if the value has length zero.

andre-volvo commented 4 months ago

Oh my god this fixed my issues, thanks a LOT! 🥰

Weakky commented 3 months ago

Hey @descawed,

Apologies for the long delay in getting this PR reviewed. We're merging this now, thank you for the contribution 🙏