Repository navigation
fix(cbor): replace invalid UTF-8 in text strings - #853
Open
YouKnowChatta wants to merge 1 commit into
Open
YouKnowChatta wants to merge 1 commit into
YouKnowChatta wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
With
-tags binary_log,log.Log().Str("value", "caf\u00e9\xff\xfe").Send()produces a record thatcbor2rejects withCBORDecodeError: error decoding text string.AppendStringwrote the original bytes under a CBOR text string header, which requires valid UTF-8. Replace each invalid byte with U+FFFD before calculating the length. The same record now decodes to{"value":"caf�"}, matching the value from the default JSON build.TestAppendInvalidUTF8Stringfails before the fix and passes with it. The race suites pass in both build modes on Linux with Go 1.23.12, 1.24.13, and 1.27.4.go vetpasses in both modes on Go 1.27.4.The invalid UTF-8 row moves out of
encodeStringTests, which expected the raw byte in the encoded output, intoTestDecodeInvalidUTF8String, so the decoder's handling of malformed text keeps its test. The UTF-8 check adds time to every string write: with-tags binary_logon an i7-10750H,BenchmarkAppendString/NoEncodinggoes from 7.4 to 26.0 ns/op andBenchmarkInfofrom 14.4 to 23.5 ns/op, with no new allocations.