Skip to content

Fix integer underflow in assertion in SparseFixedBitSet#16347

Merged
romseygeek merged 1 commit into
apache:mainfrom
romseygeek:fixedbitset/overflow
Jul 3, 2026
Merged

Fix integer underflow in assertion in SparseFixedBitSet#16347
romseygeek merged 1 commit into
apache:mainfrom
romseygeek:fixedbitset/overflow

Conversation

@romseygeek

Copy link
Copy Markdown
Contributor

For values close to Integer.MAX_VALUE, the blockCount calculation in SparseFixedBitSet can result in an assertion tripping. The method checks that the calculated block count will cover the full length of the bitset; if the block count covers the whole integer range, the check will underflow to a negative value, which compares as smaller than the passed-in length. This is fixed by a simple cast to long.

Note that the error is only in the assertion; the actual calculated block count is correct and there is no production bug.

For values close to Integer.MAX_VALUE, the blockCount calculation in
SparseFixedBitSet can result in an assertion tripping.  The method
checks that the calculated block count will cover the full length
of the bitset; if the block count covers the whole integer range,
the check will underflow to a negative value, which compares as
smaller than the passed-in length.  This is fixed by a simple cast
to long.

Note that the error is only in the assertion; the actual calculated
block count is correct and there is no production bug.
@romseygeek romseygeek self-assigned this Jul 2, 2026
@romseygeek romseygeek added the skip-changelog Apply to PRs that don't need a changelog entry, stopping the automated changelog check. label Jul 2, 2026
@romseygeek

Copy link
Copy Markdown
Contributor Author

Elasticsearch CI uncovered this - it's very rare, the randomised test in question has been running for a year and only just found the bug.

@romseygeek romseygeek merged commit ffb86f9 into apache:main Jul 3, 2026
12 of 13 checks passed
romseygeek added a commit that referenced this pull request Jul 3, 2026
For values close to Integer.MAX_VALUE, the blockCount calculation in
SparseFixedBitSet can result in an assertion tripping.  The method
checks that the calculated block count will cover the full length
of the bitset; if the block count covers the whole integer range,
the check will underflow to a negative value, which compares as
smaller than the passed-in length.  This is fixed by a simple cast
to long.

Note that the error is only in the assertion; the actual calculated
block count is correct and there is no production bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:core/other skip-changelog Apply to PRs that don't need a changelog entry, stopping the automated changelog check.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants