measure text strings by byte length in maybe_stringref#314
Merged
agronholm merged 6 commits intoJun 28, 2026
Conversation
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.
String reference threshold counts code points, not encoded bytes
While following up on the namespace fix in #313 I lined
maybe_stringrefup against the decoder and found a second place they disagree that the threshold table does not cover: the encoder decides whether to register a string withvalue.len(), which for astris the number of code points, while the length written on the wire and the decoder both count UTF-8 bytes. For any non-ASCII text the two sides then make opposite decisions about crossing the 3/4/5/7/11-byte threshold, the namespace indices drift apart, and subsequent tag 25 references resolve to the wrong earlier string, so the payload comes back silently corrupted instead of erroring. The text branch now measures UTF-8 byte length to match the decoder and the encoded form; bytestrings were already counted in bytes. The added regression round-trips a non-ASCII payload that previously decoded incorrectly.