Skip to content

Commit

Permalink
colblk: fix panic in Invert
Browse files Browse the repository at this point in the history
Fix a panic where Invert would pass a negative number into slices.Grow if bits
at indices higher than `nRows` have been set.
  • Loading branch information
jbowens committed Oct 1, 2024
1 parent b56d1b9 commit fe3e294
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sstable/colblk/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ func (b *BitmapBuilder) Invert(nRows int) {
b.minNonZeroRowCount = 1
// If the tail of b is sparse, fill in zeroes before inverting.
nBitmapWords := (nRows + 63) >> 6
b.words = slices.Grow(b.words, nBitmapWords-len(b.words))[:nBitmapWords]
if len(b.words) < nBitmapWords {
b.words = slices.Grow(b.words, nBitmapWords-len(b.words))
}
b.words = b.words[:nBitmapWords]
for i := range b.words {
b.words[i] = ^b.words[i]
}
Expand Down
15 changes: 15 additions & 0 deletions sstable/colblk/testdata/bitmap
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,18 @@ Binary representation:
32-40: b 0000000000011100000000000000000000000000000000000000000000000000 # bitmap word 3
40-48: b 0000000000000000000000000000000000000000000000000000000000000000 # bitmap word 4
48-56: b 0000100000000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

# Test a case where we invert a bitmap that has more words than we'll need in
# the finished serialized bitmap. Regression test for a bug that caused us to
# pass a negative number into slices.Grow.

build rows=64 invert
0000000000000000000000000000000000000000000000000000000000000000
1
----
1111111111111111111111111111111111111111111111111111111111111111
Binary representation:
00-01: x 00 # bitmap encoding
01-08: x 00000000000000 # padding to align to 64-bit boundary
08-16: b 1111111111111111111111111111111111111111111111111111111111111111 # bitmap word 0
16-24: b 0000000100000000000000000000000000000000000000000000000000000000 # bitmap summary word 0-63

0 comments on commit fe3e294

Please sign in to comment.