From cb925113da3eff6bb26d344c7c003f1a4132f2bd Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Thu, 3 Aug 2023 20:51:08 -0700 Subject: [PATCH] Fix panic attempting to encode zero sized webp --- src/codecs/webp/encoder.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/codecs/webp/encoder.rs b/src/codecs/webp/encoder.rs index 091dc1e967..0383046079 100644 --- a/src/codecs/webp/encoder.rs +++ b/src/codecs/webp/encoder.rs @@ -94,7 +94,11 @@ impl WebPEncoder { }; // Validate dimensions upfront to avoid panics. - if !SampleLayout::row_major_packed(color.channel_count(), width, height).fits(data.len()) { + if width == 0 + || height == 0 + || !SampleLayout::row_major_packed(color.channel_count(), width, height) + .fits(data.len()) + { return Err(ImageError::Parameter(ParameterError::from_kind( ParameterErrorKind::DimensionMismatch, )));