Return an error for zero-size images

This commit is contained in:
Jonathan Behrens committed 2022-09-05 12:44:42 -07:00
1 parent 0311402999
commit ef3294d1fe
2 files changed
+8 -1

No files matched your search

+3
View File
@@ -97,6 +97,9 @@ 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::InconsistentSizesEncountered));
}
let photometric_interpretation = tag_reader let photometric_interpretation = tag_reader
.find_tag(Tag::PhotometricInterpretation)? .find_tag(Tag::PhotometricInterpretation)?
+5 -1
View File
@@ -12,7 +12,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 +349,10 @@ 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::InconsistentSizesEncountered));
}
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);