Skip to content

avoid signed left-shift overflow in blosclz byte readers - #410

Open
suraiya-ctrl wants to merge 1 commit into
Blosc:mainfrom
suraiya-ctrl:blosclz-signed-shift-ub
Open

suraiya-ctrl wants to merge 1 commit into
Blosc:mainfrom
suraiya-ctrl:blosclz-signed-shift-ub

Conversation

@suraiya-ctrl

Copy link
Copy Markdown
Contributor

On strict-alignment targets the blosclz byte readers overflow a signed int:

  • BLOSC_STRICT_ALIGN stays defined on ARM (Apple Silicon, Graviton), RISC-V and every non-x86/non-PPC build, so those platforms use the macro variant in blosclz.c
  • BLOSCLZ_READU32 evaluates (p)[3]<<24; the byte promotes to int, so the shift lands in the sign bit whenever the fourth byte is >= 0x80, which is signed-integer overflow (UB)
  • these readers run on the compression input in blosclz_compress and get_cratio, so real data trips it on almost every block

UBSan on a plain compress of ordinary data:

blosc/blosclz.c:361:9: runtime error: left shift of 171 by 24 places cannot be represented in type 'int'

Casting each byte to uint32_t keeps the shifts unsigned and yields the same value the non-strict *(const uint32_t*) fast path already returns. UBSan is clean after the change and the full ctest suite passes on arm64 (the strict-align path).

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