Repository navigation
Use the true end of the buffer in serialize() with a header - #593
Merged
Merged
Conversation
serialize(header_size_bytes) set end_ptr to ptr + size, where ptr is already past the header and size includes it, so the end was header_size_bytes past the buffer. The same as #591 fixed for EBPPS, in var_opt, tuple, KLL, density, REQ, frequent items and classic quantiles: - The capacity checks of the serde used that end, so a serde that wrote more than size_of_item() reported could write past the buffer. - Density compared its output with that end and threw whenever a header size was given. REQ: get_serialized_size_bytes() counted a compactor header for 2 to 4 items, which are written as raw items without one, so serialize() to bytes returned 20 trailing zero bytes that the stream form doesn't have. Tests: serialize with a header and deserialize the bytes after it, and check that a serde that under-reports the size of its items is stopped by its capacity check. A test helper, undersized_string_serde, is added to common/test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage Report for CI Build 44818621979Coverage increased (+0.03%) to 97.078%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions2 previously-covered lines in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
Both serialize() overloads copied the items and weights into raw allocations for the serde, and freed them only after it returned, so a serde or copy that threw leaked them. The new header test in this PR made the serde throw and LeakSanitizer on Linux caught it. The copies are now held in vectors. The serialized bytes are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A purge can clear every counter while the sketch stays non-empty. serialize() then reserved zero-length vectors and passed their null data() to memcpy, which UBSan reports on Linux in "purge clearing all counters serialized form". Co-Authored-By: Claude Opus 5.5 <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.
Follow-up to #591, which fixed this for EBPPS. The same line is in seven more sketches: var_opt, tuple, KLL, density, REQ, frequent items and classic quantiles.
serialize(header_size_bytes)setend_ptr = ptr + size, whereptris already past the header andsizeincludes it, so the end washeader_size_bytespast the buffer.What that did:
size_of_item()reported could write past the buffer instead of throwingstd::out_of_range.serialize()threw whenever a header size was given.While testing this I found that REQ's
get_serialized_size_bytes()counted a compactor header for 2 to 4 items, which are written as raw items without one.serialize()to bytes therefore returned 20 trailing zero bytes that the stream form doesn't have. The size now matches what is written. Deserializing the longer images still works, since the trailing bytes are ignored. The cross-language snapshots are written with the stream form, so they don't change.Tests:
undersized_string_serde, is added tocommon/test. On master these tests overflow the buffer under ASan.get_serialized_size_bytes()agree for 1 to 6 items.Frequent items: both
serialize()overloads copied the items into a raw allocation for the serde and freed it only after the serde returned, so a serde (or an item copy) that threw leaked the copies. The new header test made the serde throw, and LeakSanitizer in CI caught it (0a8b021). The copies are now held in vectors; the bytes are unchanged. A new test withtest_allocatorand a serde that always throws checks both overloads.All new tests fail on master and pass here. All tests pass under ASan and UBSan.
🤖 Generated with Claude Code