Skip to content

Commit 2abd5bb

Browse files
committed
chore: lint
Signed-off-by: Shreyas220 <shreyas.ny@gmail.com>
1 parent 13e9e30 commit 2abd5bb

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

table/dv/roaring_bitmap.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
// deserialization. This prevents CPU/memory exhaustion from absurd counts
3535
// in malformed input. Derived from puffin.DefaultMaxBlobSize / 8 (minimum
3636
// per-bitmap overhead: 4-byte key + at least 4 bytes of roaring data).
37-
var maxBitmapCount = int64(puffin.DefaultMaxBlobSize / 8)
37+
var maxBitmapCount = uint64(puffin.DefaultMaxBlobSize / 8)
3838

3939
// RoaringPositionBitmap supports 64-bit positions using a sparse map of
4040
// 32-bit Roaring bitmaps. Positions are split into a 32-bit key
@@ -53,9 +53,7 @@ func NewRoaringPositionBitmap() *RoaringPositionBitmap {
5353
}
5454

5555
// Set marks a position in the bitmap.
56-
// Position must be non-negative.
5756
func (b *RoaringPositionBitmap) Set(pos uint64) {
58-
5957
key := uint32(pos >> 32)
6058
low := uint32(pos)
6159
bm, ok := b.bitmaps[key]
@@ -127,13 +125,10 @@ func (b *RoaringPositionBitmap) Serialize(w io.Writer) error {
127125
func DeserializeRoaringPositionBitmap(data []byte) (*RoaringPositionBitmap, error) {
128126
r := bytes.NewReader(data)
129127

130-
var count int64
128+
var count uint64
131129
if err := binary.Read(r, binary.LittleEndian, &count); err != nil {
132130
return nil, fmt.Errorf("read bitmap count: %w", err)
133131
}
134-
if count < 0 {
135-
return nil, fmt.Errorf("invalid bitmap count: %d", count)
136-
}
137132
if count > maxBitmapCount {
138133
return nil, fmt.Errorf("bitmap count %d exceeds maximum allowed %d", count, maxBitmapCount)
139134
}

table/dv/roaring_bitmap_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ func TestDeserializeRoaringBitmapTruncatedInput(t *testing.T) {
7979
assert.ErrorContains(t, err, "read bitmap count")
8080
}
8181

82-
// Why: negative bitmap counts are invalid and should be rejected before any further decoding.
83-
// Condition: count field encoded as -1.
84-
// Assertion: returns an error containing "invalid bitmap count".
85-
func TestDeserializeRoaringBitmapNegativeCount(t *testing.T) {
82+
// Why: counts with the high bit set (e.g. an int64 -1 written to disk) decode
83+
// as a huge uint64 and must be rejected by the upper-bound check, not silently
84+
// accepted as a small value or panicked on by make(map, hugeHint).
85+
// Condition: count field encoded as int64(-1) (= 0xFFFF_FFFF_FFFF_FFFF on disk).
86+
// Assertion: returns an error containing "exceeds maximum".
87+
func TestDeserializeRoaringBitmapHighBitCount(t *testing.T) {
8688
var buf bytes.Buffer
8789
require.NoError(t, binary.Write(&buf, binary.LittleEndian, int64(-1)))
8890

8991
_, err := DeserializeRoaringPositionBitmap(buf.Bytes())
90-
assert.ErrorContains(t, err, "invalid bitmap count")
92+
assert.ErrorContains(t, err, "exceeds maximum")
9193
}
9294

9395
// Why: absurdly large counts should be rejected to prevent CPU/memory exhaustion.

0 commit comments

Comments
 (0)