Skip to content

Fix int overflow in FluentBitSet.setInclusive at Integer.MAX_VALUE#1751

Merged
garydgregory merged 1 commit into
apache:masterfrom
alhudz:fluentbitset-setinclusive-overflow
Jul 17, 2026
Merged

Fix int overflow in FluentBitSet.setInclusive at Integer.MAX_VALUE#1751
garydgregory merged 1 commit into
apache:masterfrom
alhudz:fluentbitset-setinclusive-overflow

Conversation

@alhudz

@alhudz alhudz commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Repro: new FluentBitSet().setInclusive(0, Integer.MAX_VALUE) throws IndexOutOfBoundsException: toIndex < 0: -2147483648, and so does setInclusive(Integer.MAX_VALUE, Integer.MAX_VALUE).

Cause: setInclusive converts the inclusive toIndex into BitSet.set's exclusive upper bound with toIndex + 1, which overflows to Integer.MIN_VALUE when toIndex is Integer.MAX_VALUE. The Javadoc only documents a throw when an index is negative or fromIndex is larger than toIndex, so a legal top-of-range call throws instead of setting the bits.

Fix: special-case toIndex == Integer.MAX_VALUE so the range and the top bit are set without the overflowing increment; every other input keeps the existing single set call. The regression test is guarded by @EnabledIfSystemProperty(named = "test.large.heap", matches = "true") like the existing large-heap test, since bit Integer.MAX_VALUE needs the full backing array; it fails on the current code and passes with the fix.

@garydgregory garydgregory changed the title fix int overflow in FluentBitSet.setInclusive at Integer.MAX_VALUE Fix int overflow in FluentBitSet.setInclusive at Integer.MAX_VALUE Jul 17, 2026
@garydgregory
garydgregory merged commit 1d10448 into apache:master Jul 17, 2026
4 of 21 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