From 109c73e0bc91c05de2199d2a78d748ea2a7daf5b Mon Sep 17 00:00:00 2001 From: n4n5 Date: Tue, 16 Dec 2025 22:23:07 -0700 Subject: [PATCH 1/3] Change assert to error --- crates/resvg/src/filter/composite.rs | 12 +++++++++--- crates/resvg/src/filter/mod.rs | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/resvg/src/filter/composite.rs b/crates/resvg/src/filter/composite.rs index b4b231b6d..c17e8f72b 100644 --- a/crates/resvg/src/filter/composite.rs +++ b/crates/resvg/src/filter/composite.rs @@ -21,9 +21,14 @@ pub fn arithmetic( src1: ImageRef, src2: ImageRef, dest: ImageRefMut, -) { - assert!(src1.width == src2.width && src1.width == dest.width); - assert!(src1.height == src2.height && src1.height == dest.height); +) -> Result<(), String> { + if src1.width != src2.width || src1.width != dest.width { + return Err("Width mismatch".to_string()); + } + + if src1.height != src2.height || src1.height != dest.height { + return Err("Height mismatch".to_string()); + } let calc = |i1, i2, max| { let i1 = i1 as f32 / 255.0; @@ -49,4 +54,5 @@ pub fn arithmetic( i += 1; } + Ok(()) } diff --git a/crates/resvg/src/filter/mod.rs b/crates/resvg/src/filter/mod.rs index c70001a36..906ed713d 100644 --- a/crates/resvg/src/filter/mod.rs +++ b/crates/resvg/src/filter/mod.rs @@ -747,7 +747,8 @@ fn apply_composite( pixmap1.as_image_ref(), pixmap2.as_image_ref(), pixmap.as_image_ref_mut(), - ); + ) + .map_err(|_e| Error::InvalidRegion)?; return Ok(Image::from_image(pixmap, cs)); } From 743ba53d3509cfa062ffb877739107963d88b952 Mon Sep 17 00:00:00 2001 From: n4n5 Date: Mon, 12 Jan 2026 20:23:54 -0700 Subject: [PATCH 2/3] rm comment --- crates/resvg/src/filter/composite.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/resvg/src/filter/composite.rs b/crates/resvg/src/filter/composite.rs index c17e8f72b..0b919e162 100644 --- a/crates/resvg/src/filter/composite.rs +++ b/crates/resvg/src/filter/composite.rs @@ -9,10 +9,6 @@ use usvg::ApproxZeroUlps; /// /// - `src1` and `src2` image pixels should have a **premultiplied alpha**. /// - `dest` image pixels will have a **premultiplied alpha**. -/// -/// # Panics -/// -/// When `src1`, `src2` and `dest` have different sizes. pub fn arithmetic( k1: f32, k2: f32, From f2bda4a59e10b12ce22e86e8ce4d2f52e9e55054 Mon Sep 17 00:00:00 2001 From: n4n5 Date: Mon, 12 Jan 2026 20:34:09 -0700 Subject: [PATCH 3/3] use error --- crates/resvg/src/filter/composite.rs | 8 ++++---- crates/resvg/src/filter/mod.rs | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/resvg/src/filter/composite.rs b/crates/resvg/src/filter/composite.rs index 0b919e162..236108fa6 100644 --- a/crates/resvg/src/filter/composite.rs +++ b/crates/resvg/src/filter/composite.rs @@ -1,7 +1,7 @@ // Copyright 2020 the Resvg Authors // SPDX-License-Identifier: Apache-2.0 OR MIT -use super::{f32_bound, ImageRef, ImageRefMut}; +use super::{f32_bound, Error, ImageRef, ImageRefMut}; use rgb::RGBA8; use usvg::ApproxZeroUlps; @@ -17,13 +17,13 @@ pub fn arithmetic( src1: ImageRef, src2: ImageRef, dest: ImageRefMut, -) -> Result<(), String> { +) -> Result<(), Error> { if src1.width != src2.width || src1.width != dest.width { - return Err("Width mismatch".to_string()); + return Err(Error::InvalidRegion); } if src1.height != src2.height || src1.height != dest.height { - return Err("Height mismatch".to_string()); + return Err(Error::InvalidRegion); } let calc = |i1, i2, max| { diff --git a/crates/resvg/src/filter/mod.rs b/crates/resvg/src/filter/mod.rs index 906ed713d..a2acdc3ac 100644 --- a/crates/resvg/src/filter/mod.rs +++ b/crates/resvg/src/filter/mod.rs @@ -747,8 +747,7 @@ fn apply_composite( pixmap1.as_image_ref(), pixmap2.as_image_ref(), pixmap.as_image_ref_mut(), - ) - .map_err(|_e| Error::InvalidRegion)?; + )?; return Ok(Image::from_image(pixmap, cs)); }