[ISSUE #8262]Fix bitsarray off by one#10506
Merged
Merged
Conversation
Replace five outdated commands (updateAclConfig, deleteAccessConfig, updateGlobalWhiteAddr, clusterAclConfigVersion, getAclConfig) with the six commands available in RocketMQ 5.5.0: createAcl, updateAcl, deleteAcl, getAcl, listAcl, copyAcl Verified: all five old commands return 'sub command not exist' on RocketMQ 5.5.0. Each new command documented with parameters and usage examples from actual mqadmin -h output. Fixes apache#10502
**Bug fix** checkBytePosition and checkBitPosition used '>' instead of '>=', allowing positions equal to array length to pass validation and cause ArrayIndexOutOfBoundsException instead of the intended IllegalArgumentException. **Production impact if not fixed** Minimal. getByte/setByte are only called internally by xor/or/and with safe bounds. getBit/setBit positions come from BloomFilterData hash functions which always produce in-range values. The incorrect check has no known production trigger. **Impact of fix** Zero negative impact. All valid positions (0 to length-1) unchanged. Edge case now correctly throws IllegalArgumentException instead of ArrayIndexOutOfBoundsException. **Tests added** - BitsArrayTest: 27 tests covering create, bit/byte ops, boundary, including regression tests for the fixed checks - PlainAccessConfigTest: 12 tests for getters/setters, equals/hashCode References apache#8262
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #10506 +/- ##
=============================================
- Coverage 48.13% 48.11% -0.02%
- Complexity 13355 13365 +10
=============================================
Files 1377 1377
Lines 100707 100707
Branches 13010 13010
=============================================
- Hits 48477 48457 -20
- Misses 46296 46302 +6
- Partials 5934 5948 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
RockteMQ-AI
reviewed
Jun 15, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Review by github-manager-bot
Summary
Fixes an off-by-one error in BitsArray.checkBytePosition() and BitsArray.checkBitPosition() where > should be >= for boundary checks. Adds comprehensive tests for the boundary conditions. Fixes #8262.
Findings
- [Info]
BitsArray.java:44,52— The fix from>to>=is correct. For a byte array of length N, valid indices are 0 to N-1. Position N should triggerIllegalArgumentException, not fall through to causeArrayIndexOutOfBoundsException. - [Info]
BitsArrayTest.java— Test additions are thorough:testCheckBytePositionBoundary()andtestCheckBitPositionBoundary()specifically test the boundary values (N-1 should pass, N should throw). The refactored test methods (testGetByte,testSetByte, etc.) improve overall test coverage. - [Info]
FilterTest.java— New test class forBitsArrayfilter operations provides good integration-level coverage.
Suggestions
- The large diff (455+ lines) is mostly test additions and refactoring, which is appropriate for a bug fix that needs comprehensive boundary testing.
- Consider adding a test for
BitsArraywith size 0 or 1 to verify edge cases at the minimum boundary.
Clean bug fix with excellent test coverage. Fixes #8262. 👍
Automated review by github-manager-bot
ShannonDing
approved these changes
Jun 15, 2026
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.
Which Issue(s) This PR Fixes
Fixes #8262
Brief Description
This PR fixes an off-by-one error in the boundary checks of
BitsArray.checkBytePositionandBitsArray.checkBitPositionin the filter module.
The two methods use
>instead of>=when checking whethera position is out of bounds:
checkBytePosition: if (bytePos > byteLength()) // should be >=
checkBitPosition: if (bitPos > bitLength()) // should be >=
For a byte array of length N, valid indices are 0 through N-1.
Position N is the first invalid index, so the check should use
>=.With the old code, position N passes the check and causes
ArrayIndexOutOfBoundsExceptioninstead of the intendedIllegalArgumentExceptionwith a descriptive message.Production impact if not fixed: Minimal.
getByte/setByteareonly called internally by
xor/or/andwith guaranteed safebounds.
getBit/setBitpositions come fromBloomFilterDatahashfunctions which always produce in-range values. No known production
trigger exists.
Impact of the fix: Zero behavioral change for all valid positions
(0 to length-1). Only the boundary case is corrected.
Additionally, this PR adds unit tests to improve code coverage
for the filter and auth modules:
BitsArrayTest(27 tests): coverscreate(bitLength, bytes,bytes+bitLength),
setBit/getBit,setByte/getByte,xor,or,and(array-level and bit-level),not,clone,toString, large bit arrays, and boundary/edge cases includingregression tests for the fixed checks.
PlainAccessConfigTest(12 tests): covers getters/setters,topicPerms/groupPerms,equals(same object, identicalconfigs, different fields, null, different class),
hashCodeconsistency, and
toString.How Did You Test This Change?
IllegalArgumentExceptionat boundary positions.cause
ArrayIndexOutOfBoundsExceptioninstead.mvn test -pl filter -Dtest=BitsArrayTestandmvn test -pl auth -Dtest=PlainAccessConfigTest— bothBUILD SUCCESS.