fix(ext/image): handle bitmaps in createImageBitmap correctly#34285
Conversation
Deno Individual Contributor License AgreementAll contributors have signed the CLA. Thank you! This is an automated message from CLA Assistant |
bartlomieju
left a comment
There was a problem hiding this comment.
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)
Closes #34271
Summary
As noted in the related issue
createImageBitmapcurrently panics. This occurs becauseprocess_image_buffer_from_raw_bytesonly 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.