From a3a434ac924cb0d8f0c30ff704a01f01031c7fbb Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 19 Mar 2026 18:23:00 -0400 Subject: [PATCH] fix(wgpu): bounds check for images --- wgpu/src/image/atlas.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs index bbd71d4e..0432e4eb 100644 --- a/wgpu/src/image/atlas.rs +++ b/wgpu/src/image/atlas.rs @@ -346,6 +346,24 @@ impl Atlas { let pad_h = padding.height as usize; let stride = PIXEL * w; + // bounds check for source pixels to fragment + if pixels.len() < offset + PIXEL * image_width as usize * h { + return; + } + + // bounds check for pad_w low / high to fragment + if pad_w > 0 + && (offset + stride < PIXEL + || offset + + image_width as usize + * PIXEL + * (h.checked_sub(1).unwrap_or(0)) + + PIXEL + > pixels.len()) + { + return; + } + // Copy image rows for row in 0..h { let src = offset + row * PIXEL * image_width as usize;