Avoid integer overflow in bucket count - #223
Closed
arkmish wants to merge 1 commit into
Closed
Conversation
Promote bucket-count addition to long arithmetic so large configured bucket sizes cannot wrap the count to zero or a negative value. Add an end-to-end regression test covering both writes and reads. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
arkmish
requested review from
LZD-PratyushBhatt,
laxman-ch,
ngngwr and
thestreak101
as code owners
August 10, 2026 05:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues
No linked issue. This overflow was identified while reviewing #221.
Description
The bucket-count calculation added two positive
intvalues before dividing. For sufficientlylarge configured bucket sizes or payloads, that addition wrapped to zero or a negative value,
causing writes or reads to use the wrong number of buckets.
For example, with a 100-byte compressed payload and
bucketSize = Integer.MAX_VALUE, the expectedbucket count is 1. The existing
intcalculation evaluates(100 + 2_147_483_647 - 1) / 2_147_483_647; its numerator wraps to-2_147_483_550, so Javacomputes 0 buckets. The writer stores only metadata, and the reader reconstructs a zero-filled
buffer that fails GZIP decompression.
Promote the addition to
longarithmetic in both the writer and reader before converting theresulting bucket count back to
int. There are no UI changes.Tests
The following tests are written for this issue:
testWriteAndReadWhenBucketCountAdditionOverflowsLocal code review completed
The following is the result of the "mvn test" command on the appropriate module:
mvn test -pl helix-core -am -Dtest=TestZkBucketDataAccessor -DfailIfNoTests=falseTests run: 6, Failures: 0, Errors: 0, Skipped: 0BUILD SUCCESSChanges that Break Backward Compatibility (Optional)
None.
Documentation (Optional)
Not applicable.
Commits
this narrowly scoped arithmetic fix.
Code Quality
🤖 Generated with GitHub Copilot CLI