Skip to content

Fix RemoveRange for out-of-domain starts - #601

Merged
lemire merged 1 commit into
RoaringBitmap:masterfrom
perfloop-oss:perfloop-pr-open-h81gxh9s3s
Dec 1, 2026
Merged

lemire merged 1 commit into
RoaringBitmap:masterfrom
perfloop-oss:perfloop-pr-open-h81gxh9s3s

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

Effect: silent wrong results. The call returns normally and deletes stored values outside the requested range; no error or panic.
Since: the end clamp added in 4a6b95e (the fix for #141) runs after the empty-range check and before rangeStart is narrowed to uint32. That has been the case in every release since v0.4.2 (2018-02-06), through the current v2.30.0 (2026-10-19).

From a checkout at 340bdf64f4bf3d3367950d9ae37b15cb5003b269, run:

cat > /tmp/removerange-repro.go <<'EOF_GO'
package main

import (
    "fmt"
    "github.com/RoaringBitmap/roaring/v2"
)

func main() {
    rb := roaring.BitmapOf(0, 1, 7, 0xffffffff)
    rb.RemoveRange(0x100000000, 0x100000001)
    fmt.Println(rb.ToArray())
}
EOF_GO
go run /tmp/removerange-repro.go

Expected:

[0 1 7 4294967295]

Actual:

[]

RemoveRange checks whether the interval is empty before clamping its upper bound to 0x100000000. It then narrows the start to uint32, wrapping this example's start to zero and removing every stored value. A larger start removes every value at or above rangeStart mod 2^32.

This change returns immediately when the start exceeds MaxUint32, before narrowing it. It retains the existing upper-bound clamping for representable starts. TestRemoveRangeOutsideDomain in roaring_test.go covers out-of-domain starts, and the existing range-end test now ensures MaxUint32 itself remains removable.

This matches IntersectsWithInterval, which already returns early for a start above MaxUint32. CardinalityInRange has the same check order; open PR #600 fixes it there.

The focused Go range-removal and copy-on-write tests passed for the 32-bit API, its 64-bit caller, and the generic fallback; the new test fails without the fix.

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart.

@lemire
lemire merged commit 1251c72 into RoaringBitmap:master Dec 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants