Skip to content

fix(codec): decode/encode UDT values as PLP regardless of MAX_LEN - #6

Open
Tawxyn wants to merge 1 commit into
Synergex:mainfrom
Tawxyn:fix/udt-plp-encoding
Open

fix(codec): decode/encode UDT values as PLP regardless of MAX_LEN#6
Tawxyn wants to merge 1 commit into
Synergex:mainfrom
Tawxyn:fix/udt-plp-encoding

Conversation

@Tawxyn

@Tawxyn Tawxyn commented Aug 25, 2026

Copy link
Copy Markdown

UDT values are always PLP-encoded on the wire (8-byte length prefix plus length-prefixed chunks). The codec instead routed them through the VARCHAR/VARBINARY path, where MAX_LEN < 0xffff selects the classic 2-byte-length format. A UDT's MAX_LEN is descriptive, not a format selector, so reads misinterpreted the first two bytes of the PLP prefix as a length and desynced the token stream — surfacing later as Protocol("invalid token type 0").

Reproduced against SQL Server 2025 with
SELECT CAST('/1/2/' AS hierarchyid), which reports MAX_LEN 892 while sending a PLP-framed value.

Split plp::decode_unknown_size out of plp::decode and call it for UDTs, and replace encode_var_len_bytes (UDT-only) with encode_udt_bytes, which always emits PLP.

Fixes the pre-existing hierarchyid_read_as_raw_clr_data tests.

UDT values are always PLP-encoded on the wire (8-byte length prefix plus
length-prefixed chunks). The codec instead routed them through the
VARCHAR/VARBINARY path, where MAX_LEN < 0xffff selects the classic
2-byte-length format. A UDT's MAX_LEN is descriptive, not a format
selector, so reads misinterpreted the first two bytes of the PLP prefix
as a length and desynced the token stream — surfacing later as
Protocol("invalid token type 0").

Reproduced against SQL Server 2025 with
`SELECT CAST('/1/2/' AS hierarchyid)`, which reports MAX_LEN 892 while
sending a PLP-framed value.

Split plp::decode_unknown_size out of plp::decode and call it for UDTs,
and replace encode_var_len_bytes (UDT-only) with encode_udt_bytes, which
always emits PLP.

Fixes the pre-existing hierarchyid_read_as_raw_clr_data tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant