fuzzing: fix serialization of strings containing null bytes#769
Open
dguido wants to merge 1 commit into
Open
Conversation
Strings containing null bytes (\x00) or other non-printable control characters were being incorrectly serialized to JSON, causing them to be lost when saved to the corpus. This fix uses hex encoding with a "hex:" prefix for strings that contain characters that cannot be reliably represented in JSON. The fix: - Add stringNeedsHexEncoding() to detect strings requiring encoding - Encode such strings as "hex:<hex-encoded-bytes>" in encodeJSONArgument - Decode hex-prefixed strings back to original bytes in decodeJSONArgument - Add comprehensive tests for round-trip serialization Fixes #279 Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.
Summary
\x00) and other non-printable control charactershex:prefixProblem
When serializing ABI values to JSON for corpus storage, strings containing null bytes were being incorrectly saved as empty strings. This is because JSON cannot properly represent arbitrary binary data in strings - null bytes and other control characters can be lost during the
[]byte -> stringconversion or JSON marshaling.Solution
The fix:
stringNeedsHexEncoding()helper to detect strings that contain null bytes, invalid UTF-8 sequences, or control characters (except common whitespace like\t,\n,\r)encodeJSONArgument(): Encode such strings ashex:<hex-encoded-bytes>decodeJSONArgument(): Decode strings with thehex:prefix back to their original bytesThis approach:
BytesTyserializationTest plan
TestStringWithNullBytes- verifies round-trip serialization for various null byte scenariosTestStringNeedsHexEncoding- verifies the helper function correctly identifies strings needing encodinggo test -v ./fuzzing/valuegeneration/...golangci-lint run --timeout 5mFixes #279
Generated with Claude Code