Skip to content

fix(ext/image): handle bitmaps in createImageBitmap correctly#34285

Merged
bartlomieju merged 1 commit into
denoland:mainfrom
turtletongue:fix/handle-rectangular-image-bitmaps
May 21, 2026
Merged

fix(ext/image): handle bitmaps in createImageBitmap correctly#34285
bartlomieju merged 1 commit into
denoland:mainfrom
turtletongue:fix/handle-rectangular-image-bitmaps

Conversation

@turtletongue
Copy link
Copy Markdown
Contributor

Closes #34271

Summary

As noted in the related issue createImageBitmap currently panics. This occurs because process_image_buffer_from_raw_bytes only maps buffer pixels along the diagonal of the image, causing an out-of-bounds error whenever the image dimensions exceed 1x1. The current unit tests only verify bitmap creation for 1x1 images, which failed to surface this issue.

@deno-cla-assistant
Copy link
Copy Markdown

deno-cla-assistant Bot commented May 21, 2026

Deno Individual Contributor License Agreement

All contributors have signed the CLA. Thank you!

Re-run CLA check


This is an automated message from CLA Assistant

Copy link
Copy Markdown
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch — the fix is correct. (index % width, index / width) is the standard row-major mapping, and it matches the panic in #34271 exactly (old code wrote pixel N to (N, N), so the first OOB write hit (min_dim, min_dim) against (width, height), which is exactly what the issue showed: Image index (1594, 1594) out of bounds (2400, 1594)).

Coverage looks good too: the new Rust unit test exercises a 3x2 buffer and asserts the last pixel (which hits both the % and the /), and the TS test was switched from the 1x1 PNG (which happened to work even with the bug) to a 160x320 JPEG so the end-to-end path now actually exercises the rectangular case.

The new doc comment ("width and height are expected to be non-zero") is accurate — the sole caller create_image_from_raw_bytes already returns InvalidSizeZero for zero dimensions, so the % width here can't divide by zero.

No blocking concerns. Just leaving CI to finish — happy to see this land once it goes green.

@bartlomieju LGTM, needs maintainer signoff (first-time contributor)

Copy link
Copy Markdown
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@bartlomieju bartlomieju merged commit 99babcf into denoland:main May 21, 2026
136 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.

panic in createImageBitmap resize: "Image index (h, h) out of bounds (w, h)"

2 participants