Skip to content

Commit

Permalink
Fix panic attempting to encode zero sized webp
Browse files Browse the repository at this point in the history
  • Loading branch information
fintelia committed Aug 4, 2023
1 parent 814596e commit cb92511
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/codecs/webp/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ impl<W: Write> WebPEncoder<W> {
};

// 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,
)));
Expand Down

0 comments on commit cb92511

Please sign in to comment.