Skip to content

fix out-of-bounds write in blosc_getitem for negative nitems - #406

Merged
FrancescAlted merged 1 commit into
Blosc:mainfrom
suraiya-ctrl:getitem-negative-nitems
Oct 26, 2026
Merged

FrancescAlted merged 1 commit into
Blosc:mainfrom
suraiya-ctrl:getitem-negative-nitems

Conversation

@suraiya-ctrl

Copy link
Copy Markdown
Contributor

blosc_getitem() rejects an out-of-range start and start+nitems, but never checks nitems on its own, and runs the checks in 32-bit:

  • a negative nitems with start > |nitems| passes all four bound checks
  • the per-block length bsize2 = stopb - startb then goes negative and reaches fastcopy() as a size_t, writing past dest (ASAN reports a heap-buffer-overflow in blosc_getitem -> fastcopy)
  • starttypesize and stoptypesize also overflow int for a large out-of-range start, so that check can be skipped too

Reject nitems < 0 and do the range math in int64_t. tests/test_getitem_bounds.c faults under AddressSanitizer on the current code and passes with the fix; the existing getitem round-trips are unchanged.

blosc_getitem checked start and start+nitems against the buffer but
never nitems itself, and did the checks with 32-bit multiplication. A
negative nitems (with start > |nitems|) passed every bound, bsize2 =
stopb - startb went negative, and fastcopy() received it as a size_t,
writing far past dest. Reject nitems < 0 and do the range math in
int64_t so the start*typesize checks cannot overflow either.
@FrancescAlted

Copy link
Copy Markdown
Member

LGTM. Thanks @suraiya-ctrl !

@FrancescAlted
FrancescAlted merged commit 234db70 into Blosc:main Oct 26, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants