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, )));