Skip to content

Commit

Permalink
Merge pull request #1971 from fintelia/webp-encode-zero
Browse files Browse the repository at this point in the history
Fix panic attempting to encode zero sized webp
  • Loading branch information
fintelia authored Aug 4, 2023
2 parents 814596e + cb92511 commit 31ecbe6
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 31ecbe6

Please sign in to comment.