Skip to content

Bugfix/jpeg overflow guard - #327

Merged
mlarouche merged 2 commits into
zigimg:masterfrom
IfkumRfnl:bugfix/jpeg-overflow-guard
May 31, 2026
Merged

Bugfix/jpeg overflow guard#327
mlarouche merged 2 commits into
zigimg:masterfrom
IfkumRfnl:bugfix/jpeg-overflow-guard

Conversation

@IfkumRfnl

Copy link
Copy Markdown
Contributor

Summary

Fixes #324 by returning Unsupported before the decoder reaches overflowing fixed-point arithmetic.

Details

  • Checks JPEG dequantization multiplication and returns Image.ReadError.Unsupported on overflow.
  • Rejects unsupported 16 bit quantization tables in the current 8-bit JPEG decode path.
  • Adds a conservative input bound before each fixed point IDCT pass so existing i32 arithmetic cannot overflow.
  • Propagates IDCT errors through the JPEG and pipeline.
  • Tightens crafted overflow tests to expect Image.ReadError.Unsupported.

Small note: I didn't go with widening the arithmetic types since the SIMD operations underneath are currently built around i32, so I think for now just not supporting these kind of images is better.

@IfkumRfnl

Copy link
Copy Markdown
Contributor Author

@mlarouche could you review this when you have a chance? Companion fixture PR: zigimg/test-suite#39

@mlarouche
mlarouche merged commit 0dd8649 into zigimg:master May 31, 2026
3 checks passed
@stone-d-chen

Copy link
Copy Markdown
Contributor

thanks for the fix!

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.

Integer overflow in Frame.dequantizeBlocks() [on aarch64/musl]

3 participants