Guard composite-index remove against short key arrays - #776
Merged
Conversation
A hashing composite bitmap index keeps one sub-index per key-array position and grows to the longest key array ever added, never shrinking. The add, query, contains and change paths each guard every position with isEmpty(keys, i) (which tolerates i >= keys.length), but internalRemoveForKeys iterated all sub-indices unconditionally and passed the key array straight through, so a sub-index at a trailing position read keys[position] out of bounds. Removing an entity whose key array is shorter than the widest one seen therefore threw ArrayIndexOutOfBoundsException. Make remove symmetric with add and query by iterating by index and skipping empty positions via isEmpty(keys, i). Unlike add and change, remove must not call ensureSubIndices: no bit was ever set for an empty position, so there is nothing to remove there. Add a regression test covering removal of an entity with a variable-length composite key that is shorter than the widest key array previously indexed.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in GigaMap composite bitmap index removal when an entity’s composite key array is shorter than the longest key array previously indexed, by making the remove path apply the same per-position “empty” guarding used by add/query/change.
Changes:
- Hardened
AbstractCompositeBitmapIndex.internalRemoveForKeysto skip “empty” (including out-of-range) key positions instead of iterating sub-indices unconditionally. - Added a regression test covering variable-length composite key arrays during removal.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| gigamap/gigamap/src/main/java/org/eclipse/store/gigamap/types/AbstractCompositeBitmapIndex.java | Makes composite-index removal symmetric with add/query by guarding per-position with isEmpty(keys, i) to avoid out-of-bounds access. |
| gigamap/gigamap/src/test/java/org/eclipse/store/gigamap/indexer/CompositeIndexNullHandlingTest.java | Adds a regression test reproducing and preventing the variable-length composite-key removal crash. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
zdenek-jonas
approved these changes
Jul 23, 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.
Problem
Removing an entity from a
GigaMapthat carries a hashing composite bitmap index throwsArrayIndexOutOfBoundsExceptionwhen the removed entity's key array is shorter than the widest key array the index has ever seen.A composite index keeps one sub-index per key-array position and grows
subIndicesto the longest key array added so far (positions are never removed). The add, query, contains and change paths each guard every position withisEmpty(keys, i)(which toleratesi >= keys.length), butAbstractCompositeBitmapIndex.internalRemoveForKeysiterated all sub-indices unconditionally and passed the key array straight through, so a sub-index at a trailing position readkeys[position]out of bounds.Reproducer
Entity A has two tags, so the index grows to two sub-indices. Entity B has one tag (position 1 skipped on add via
isEmpty).removeById(B)then readskeys[1]on a length-1 array and throwsArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1.Fix
Make remove symmetric with add and query: iterate by index and skip empty positions via
isEmpty(keys, i). Unlike the add and change paths, remove must not callensureSubIndices— no bit was ever set for an empty position, so there is nothing to remove there. This mirrors the existing guard oninternalHandleChanged, which was previously hardened against the same hazard.Tests
Added a regression test (
CompositeIndexNullHandlingTest.variableLengthCompositeKeyRemoveShouldWork) that removes an entity whose composite key array is shorter than the widest one previously indexed. It reproduces the exactIndex 1 out of bounds for length 1failure on the unpatched code and passes after the fix. The fullgigamapmodule suite passes (1079 tests, 1 slow test skipped by default).