Skip to content

fix(deletes): validate roaring bitmap after deserialization - #1005

Merged
wgtmac merged 1 commit into
apache:mainfrom
gty404:fix/roaring-bitmap-validate-deserialize
Oct 15, 2026
Merged

wgtmac merged 1 commit into
apache:mainfrom
gty404:fix/roaring-bitmap-validate-deserialize

Conversation

@gty404

@gty404 gty404 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • RoaringPositionBitmap::Deserialize relied on Roaring::readSafe, which only bounds-checks the read and does not verify CRoaring's structural invariants. A crafted deletion vector (e.g. a bitset container with a wrong cardinality, or wrapping run containers) could later cause out-of-bounds access during merge (|=) or serialize (runOptimize).
  • Call roaring_bitmap_internal_validate right after readSafe and return InvalidArgument on failure. This is the only CRoaring deserialization site, so all read/merge paths are covered.

Test plan

  • Added TestDeserializeRejectsStructurallyInvalidBitmap (bitset container claiming cardinality 4097 with all 65536 bits set); verified it fails without the fix and passes with it.
  • util_test RoaringPositionBitmap / PositionDelete tests and data_test pass.

readSafe only bounds-checks the read and does not verify CRoaring's
structural invariants. A forged deletion vector (e.g. bitset container
with a wrong cardinality or wrapping run containers) could later cause
out-of-bounds access during merge or serialize. Call
roaring_bitmap_internal_validate right after readSafe and reject invalid
bitmaps with InvalidArgument.

@zhjwpku zhjwpku left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@zhjwpku zhjwpku added the ready to merge This PR has been approved and it is ready to merge. label Oct 13, 2026

@wgtmac wgtmac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Validating the bitmap immediately after readSafe covers the only CRoaring deserialization site, so the merge (|=) and re-serialization (RunOptimize) paths are both protected, and the failure is surfaced as InvalidArgument from the existing Result API. The regression test exercises the invalid-cardinality shape; a wrapping run-container fixture would tighten coverage but is not required. Merging.

@wgtmac
wgtmac merged commit d98d851 into apache:main Oct 15, 2026
15 checks passed
@gty404
gty404 deleted the fix/roaring-bitmap-validate-deserialize branch October 15, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge This PR has been approved and it is ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants