Skip to content

Fix get_maximum_output_size overflow on 32-bit targets#205

Merged
PSeitz merged 1 commit intoPSeitz:mainfrom
dglittle:fix-get-maximum-output-size-overflow
Feb 19, 2026
Merged

Fix get_maximum_output_size overflow on 32-bit targets#205
PSeitz merged 1 commit intoPSeitz:mainfrom
dglittle:fix-get-maximum-output-size-overflow

Conversation

@dglittle
Copy link
Contributor

Fixes #204

Summary

  • Rearranges arithmetic in get_maximum_output_size to avoid input_len * 110 overflow on 32-bit targets (e.g. wasm32)
  • Adds test verifying correct results using u32 arithmetic

Problem

On wasm32, input_len * 110 overflows u32 when input_len > ~39MB, causing compress_into to receive a vastly undersized buffer and panic.

Fix

Replace input_len * 110 / 100 with input_len + input_len / 100 * 10 + input_len % 100 * 10 / 100. Produces identical results without intermediate overflow.

dglittle added a commit to braid-org/diamond-types that referenced this pull request Feb 15, 2026
Point lz4_flex dependency to dglittle/lz4_flex fork which fixes
get_maximum_output_size() overflow on 32-bit targets. The original
formula `input_len * 110 / 100` overflows u32 when input_len > ~39MB,
causing compress_into to receive an undersized buffer and panic.

See: PSeitz/lz4_flex#205

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@PSeitz
Copy link
Owner

PSeitz commented Feb 15, 2026

Thanks for the PR. I'd prefer to just cast input_size to u64.

Cast input_len to u64 before multiplying by 110, avoiding overflow on
32-bit targets (e.g. wasm32) where `input_len * 110` overflows usize
when input_len > 2^32 / 110 ≈ 39MB.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dglittle dglittle force-pushed the fix-get-maximum-output-size-overflow branch from 2fae275 to 4ff9d43 Compare February 15, 2026 08:59
@dglittle
Copy link
Contributor Author

Sounds good -- I've updated the PR. Thanks!

@PSeitz PSeitz merged commit 2991a09 into PSeitz:main Feb 19, 2026
2 of 3 checks passed
@PSeitz
Copy link
Owner

PSeitz commented Feb 19, 2026

Thanks!

rerun-sync bot pushed a commit to rerun-io/rerun that referenced this pull request Mar 17, 2026
### Related

* Closes RR-4067.
* PSeitz/lz4_flex#205

### What

This bumps `lz4_flex` to `0.13.0` which includes the PR linked above.

### Testing

1. Open web viewer
2. Open DICOM recording
3. Menu -> Save recording...
4. Should not crash

Source-Ref: b09682616fc15c6299351d3e31dc2d9a0b3c99ac
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.

get_maximum_output_size overflows on 32-bit targets (wasm32)

2 participants