Skip to content

MSSQL variable-length types are limited to u8-max length #1724

Open
@Dessix

Description

@Dessix

It seems the encoding for MSSQL does not understand strings beyond 255 characters in length, and causes the server to abort reads after sending more data than the server expects. I was attempting to make a PR to add Vec<u8> -> BigVarBinary support, but it was unclear to me how to encode variable-length types from either of the SQLX pattern perspective or the actual TSQL wire protocol.

At the very least, it seems to me that - rather than crashing - the encode should fail if it is aware that it cannot represent the type. This may also be true for other dialects, if they are susceptible to the same pattern of too-long-of-input resulting in a wire-protocol-level failure?

To reproduce:

  • Add the following test (replacing the existing str<String> one) to tests/mssql/types.rs (Yes, it's a bit verbose, but the test_type macro prevented me from using dynamically-constructed strings in its current form):
test_type!(str<String>(Mssql,
    "'01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456'"
    ==
    "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456",
    "''" == "",
));
  • Run the unit tests for mssql
  • Note that the above strings are 257 characters long; at ~560, the behaviour changes slightly with regards to timing, but the error remains the same. I'm not clear how this variable-length encoding is supposed to work, as I couldn't find documentation on what signals use of a u16 or u32 in place of the single-byte length specifier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions