Fix flaky TestSetAndGetUUIDValue: big.Int drops leading zero bytes#518
Merged
lemire merged 1 commit intoRoaringBitmap:masterfrom Mar 9, 2026
Merged
Fix flaky TestSetAndGetUUIDValue: big.Int drops leading zero bytes#518lemire merged 1 commit intoRoaringBitmap:masterfrom
lemire merged 1 commit intoRoaringBitmap:masterfrom
Conversation
…eros big.Int.Bytes() returns the minimal-length byte slice with no leading zeros. When the UUID binary representation happens to start with 0x00 (probability ~1/256), the round-trip through big.Int loses that byte, producing 15 bytes instead of 16. uuid.FromBytes then rejects the result. Fix by using big.Int.FillBytes, which left-pads with zeros to exactly fill the destination slice. Also add a deterministic regression test, TestSetAndGetUUIDValueLeadingZero, which constructs a UUID with a known leading zero byte so the failure mode can be reproduced without relying on randomness.
lemire
reviewed
Mar 9, 2026
| assert.Equal(t, bigUUID, bv) | ||
|
|
||
| newUUID, err := uuid.FromBytes(bv.Bytes()) | ||
| // big.Int.Bytes() drops leading zero bytes; use FillBytes to restore the |
Member
There was a problem hiding this comment.
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
TestSetAndGetUUIDValuefails intermittently (~1/256 runs) when the UUIDbinary representation starts with a
0x00byte.big.Int.Bytes()returnsthe minimal-length byte slice with no leading zeros, so that byte is
silently dropped, producing 15 bytes instead of 16.
uuid.FromBytesthenrejects the result with "invalid UUID (got 15 bytes)".
Fix: use
big.Int.FillBytesinstead, which left-pads with zeros toexactly fill the destination slice.
Also adds
TestSetAndGetUUIDValueLeadingZero, a deterministic regressiontest that constructs a UUID with a known leading zero byte so the failure
mode is reproducible without relying on randomness.
Verified by running
TestSetAndGetUUIDValuewith-count=500before andafter the fix: the unfixed test reliably produces a failure within that
window; the fixed test passes all 500 runs.
This was flagged by the macOS CI failure on #515, which is otherwise an
unrelated change. The Linux runners happened to not hit the 1/256 case in
that run.