From 9fd3db9484c7eb9f478c5f507d82b0a196762176 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Thu, 12 Nov 2026 06:26:19 -0500 Subject: [PATCH] craft-svg: report the decoded size of nested SVGZ input * svg: include decoded size in nested stream errors --- crates/svg/src/svgz.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/svg/src/svgz.rs b/crates/svg/src/svgz.rs index 929ad450b..1f3ca90ec 100644 --- a/crates/svg/src/svgz.rs +++ b/crates/svg/src/svgz.rs @@ -21,8 +21,8 @@ pub enum Error { Corrupt(String), /// The gzip stream holds gzip data again. A reader that unpacks what it is handed would /// unpack that second layer with no limit, so it is refused here. - #[error("the compressed SVG holds another compressed file, not a document")] - Nested, + #[error("the compressed SVG holds another compressed file, not a document ({0} decoded bytes)")] + Nested(usize), /// The text is not valid in its encoding. #[error("the SVG is not UTF-8, UTF-16 or ISO 8859-1")] Encoding, @@ -66,7 +66,7 @@ pub fn inflate(bytes: &[u8], limit: usize) -> Result, Error> { first = false; } if is_svgz(&out) { - return Err(Error::Nested); + return Err(Error::Nested(out.len())); } Ok(Cow::Owned(out)) } @@ -177,7 +177,7 @@ mod tests { let z = compress(SVG.as_bytes()); assert!(matches!(inflate(z.get(..z.len() / 2).unwrap_or_default(), MB), Err(Error::Corrupt(_)))); assert!(matches!(inflate(&[0x1f, 0x8b, 0xff], MB), Err(Error::Corrupt(_)))); - assert_eq!(inflate(&compress(&z), MB), Err(Error::Nested)); + assert_eq!(inflate(&compress(&z), MB), Err(Error::Nested(z.len()))); } #[test]