Merge pull request #176 from fintelia/zero-size

Return an error for zero-size images
This commit is contained in:
Jonathan Behrens authored and GitHub committed 2022-09-05 13:10:30 -07:00
commit 3bce92781c
3 files changed
+14

No files matched your search

+5
View File
@@ -97,6 +97,11 @@ impl Image {
let width = tag_reader.require_tag(Tag::ImageWidth)?.into_u32()?; let width = tag_reader.require_tag(Tag::ImageWidth)?.into_u32()?;
let height = tag_reader.require_tag(Tag::ImageLength)?.into_u32()?; let height = tag_reader.require_tag(Tag::ImageLength)?.into_u32()?;
if width == 0 || height == 0 {
return Err(TiffError::FormatError(TiffFormatError::InvalidDimensions(
width, height,
)));
}
let photometric_interpretation = tag_reader let photometric_interpretation = tag_reader
.find_tag(Tag::PhotometricInterpretation)? .find_tag(Tag::PhotometricInterpretation)?
+7
View File
@@ -13,6 +13,7 @@ use std::{
use crate::{ use crate::{
error::TiffResult, error::TiffResult,
tags::{CompressionMethod, ResolutionUnit, Tag}, tags::{CompressionMethod, ResolutionUnit, Tag},
TiffError, TiffFormatError,
}; };
pub mod colortype; pub mod colortype;
@@ -349,6 +350,12 @@ impl<'a, W: 'a + Write + Seek, T: ColorType, K: TiffKind, D: Compression>
height: u32, height: u32,
compression: D, compression: D,
) -> TiffResult<Self> { ) -> TiffResult<Self> {
if width == 0 || height == 0 {
return Err(TiffError::FormatError(TiffFormatError::InvalidDimensions(
width, height,
)));
}
let row_samples = u64::from(width) * u64::try_from(<T>::BITS_PER_SAMPLE.len())?; let row_samples = u64::from(width) * u64::try_from(<T>::BITS_PER_SAMPLE.len())?;
let row_bytes = row_samples * u64::from(<T::Inner>::BYTE_LEN); let row_bytes = row_samples * u64::from(<T::Inner>::BYTE_LEN);
+2
View File
@@ -56,6 +56,7 @@ pub enum TiffFormatError {
actual_samples: usize, actual_samples: usize,
required_samples: usize, required_samples: usize,
}, },
InvalidDimensions(u32, u32),
InvalidTag, InvalidTag,
InvalidTagValueType(Tag), InvalidTagValueType(Tag),
RequiredTagNotFound(Tag), RequiredTagNotFound(Tag),
@@ -100,6 +101,7 @@ impl fmt::Display for TiffFormatError {
actual_samples, required_samples actual_samples, required_samples
) )
} }
InvalidDimensions(width, height) => write!(fmt, "Invalid dimensions: {}x{}.", width, height),
InvalidTag => write!(fmt, "Image contains invalid tag."), InvalidTag => write!(fmt, "Image contains invalid tag."),
InvalidTagValueType(ref tag) => { InvalidTagValueType(ref tag) => {
write!(fmt, "Tag `{:?}` did not have the expected value type.", tag) write!(fmt, "Tag `{:?}` did not have the expected value type.", tag)