Skip to content

fix match length overflow in blosclz_decompress - #411

Open
suraiya-ctrl wants to merge 1 commit into
Blosc:mainfrom
suraiya-ctrl:blosclz-match-len-overflow
Open

suraiya-ctrl wants to merge 1 commit into
Blosc:mainfrom
suraiya-ctrl:blosclz-match-len-overflow

Conversation

@suraiya-ctrl

Copy link
Copy Markdown
Contributor

blosclz_decompress grows the length of a long match (ctrl >> 5 == 7) by adding each following 0xff byte to an int32_t len, with no upper bound:

  • a split carrying ~8.4M 0xff bytes pushes len past INT32_MAX; the wrapped negative value passes op + len > op_limit and becomes the copy size for copy_match() / memset() / wild_copy()
  • reachable from blosc_decompress, blosc_decompress_ctx and blosc_getitem on an untrusted buffer, and the header still passes blosc_cbuffer_validate
  • c-blosc2 fixed the same loop in Blosc/c-blosc2@314b8043a7 (OSS-Fuzz report); the guard here is that one, checking len > maxout - code before each addition

Repro (ASan + UBSan), one 4096-byte blosclz block whose split is an 8-byte literal followed by such a match:

blosc/blosclz.c:704:15: runtime error: signed integer overflow: 2147483526 + 255 cannot be represented in type 'int'
ERROR: AddressSanitizer: heap-buffer-overflow ... WRITE of size 2
    #0 copy_match fastcopy.c:624
    #1 blosclz_decompress blosclz.c:760
    #2 blosc_d blosc.c:782
    ...
    #5 blosc_decompress blosc.c:1577
0x... is located 0 bytes after 4096-byte region

Valid streams are unaffected: any match whose length passes maxout is already rejected by the later op + len > op_limit check. tests/test_blosclz_match_len.c crashes on the current tree and passes with the fix; the full ctest suite passes on arm64 macOS (1647/1647, and 1636/1636 under ASan/UBSan).

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.

1 participant