diff --git a/core/src/image.rs b/core/src/image.rs index be9eb1d8..f49d41be 100644 --- a/core/src/image.rs +++ b/core/src/image.rs @@ -348,6 +348,9 @@ pub enum Error { /// Loading images is unsupported. #[error("loading images is unsupported")] Unsupported, + /// The image is empty. + #[error("the image is empty")] + Empty, /// Not enough memory to allocate the image. #[error("not enough memory to allocate the image")] OutOfMemory, diff --git a/tiny_skia/src/raster.rs b/tiny_skia/src/raster.rs index 56ed8c47..e5804192 100644 --- a/tiny_skia/src/raster.rs +++ b/tiny_skia/src/raster.rs @@ -106,6 +106,10 @@ impl Cache { } }; + if image.width() == 0 || image.height() == 0 { + return Err(raster::Error::Empty); + } + let mut buffer = vec![0u32; image.width() as usize * image.height() as usize];