fix(codec): decode/encode UDT values as PLP regardless of MAX_LEN - #6
Open
Tawxyn wants to merge 1 commit into
Open
fix(codec): decode/encode UDT values as PLP regardless of MAX_LEN#6Tawxyn wants to merge 1 commit into
Tawxyn wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.