From e7a2317f5a18751ecc1a63b3464690b125839ecf Mon Sep 17 00:00:00 2001 From: Hajime-san <41257923+Hajime-san@users.noreply.github.com> Date: Tue, 7 May 2024 20:47:42 +0900 Subject: [PATCH] fix(ext/web): properly handle `Blob` case for `createImageBitmap` (#23518) fixes https://github.com/denoland/deno/issues/22649 --- ext/canvas/01_image.js | 4 +++- ext/canvas/lib.rs | 3 ++- tests/testdata/image/1x1-white.png | Bin 0 -> 109 bytes tests/unit/image_bitmap_test.ts | 11 +++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/testdata/image/1x1-white.png diff --git a/ext/canvas/01_image.js b/ext/canvas/01_image.js index a738f7992c..6fb1ee62fc 100644 --- a/ext/canvas/01_image.js +++ b/ext/canvas/01_image.js @@ -238,7 +238,9 @@ function createImageBitmap( "InvalidStateError", ); } - const { data: imageData, width, height } = op_image_decode_png(data); + const { data: imageData, width, height } = op_image_decode_png( + new Uint8Array(data), + ); const processedImage = processImage( imageData, width, diff --git a/ext/canvas/lib.rs b/ext/canvas/lib.rs index b05332c3f1..72173f1331 100644 --- a/ext/canvas/lib.rs +++ b/ext/canvas/lib.rs @@ -130,7 +130,8 @@ fn op_image_decode_png(#[buffer] buf: &[u8]) -> Result { ))); } - let mut png_data = Vec::with_capacity(png.total_bytes() as usize); + // read_image will assert that the buffer is the correct size, so we need to fill it with zeros + let mut png_data = vec![0_u8; png.total_bytes() as usize]; png.read_image(&mut png_data)?; diff --git a/tests/testdata/image/1x1-white.png b/tests/testdata/image/1x1-white.png new file mode 100644 index 0000000000000000000000000000000000000000..dd43faec54ae60a210f1eab6ff4e7c88b8e34c97 GIT binary patch literal 109 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blwj^(N7l!{JxM1({$v_d#0*}aI wAngIhZYQ(tfDB$w7sn8e>&ZX<|Nmdl!1