Improve unexpected tile count error
Do we even want to error early here? This isn't exactly fatal to reading the image it is a only nuisance. It becomes crucial only when we are at the point of reading all the tiles themselves.
This commit is contained in:
1 parent
701fcc46b8
commit
45cd3c3b63
2 files changed
+34
-9
No files matched your search
+31
-9
@@ -330,15 +330,28 @@ impl Image {
|
|||||||
strip_decoder = Some(StripDecodeState { rows_per_strip });
|
strip_decoder = Some(StripDecodeState { rows_per_strip });
|
||||||
tile_attributes = None;
|
tile_attributes = None;
|
||||||
|
|
||||||
if chunk_offsets.len() != chunk_bytes.len()
|
if chunk_offsets.len() != chunk_bytes.len() {
|
||||||
|| rows_per_strip == 0
|
|
||||||
|| u32::try_from(chunk_offsets.len())?
|
|
||||||
!= (height.saturating_sub(1) / rows_per_strip + 1) * planes as u32
|
|
||||||
{
|
|
||||||
return Err(TiffError::FormatError(
|
return Err(TiffError::FormatError(
|
||||||
TiffFormatError::InconsistentSizesEncountered,
|
TiffFormatError::InconsistentSizesEncountered,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rows_per_strip == 0 {
|
||||||
|
return Err(TiffError::FormatError(
|
||||||
|
TiffFormatError::InconsistentSizesEncountered,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if u32::try_from(chunk_offsets.len())?
|
||||||
|
!= height.div_ceil(rows_per_strip) * planes as u32
|
||||||
|
{
|
||||||
|
return Err(TiffError::FormatError(
|
||||||
|
TiffFormatError::IncorrectChunkCount {
|
||||||
|
expected: height.div_ceil(rows_per_strip) * planes as u32,
|
||||||
|
found: chunk_offsets.len() as u32,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(false, false, true, true) => {
|
(false, false, true, true) => {
|
||||||
chunk_type = ChunkType::Tile;
|
chunk_type = ChunkType::Tile;
|
||||||
@@ -371,14 +384,23 @@ impl Image {
|
|||||||
.into_u64_vec()?;
|
.into_u64_vec()?;
|
||||||
|
|
||||||
let tile = tile_attributes.as_ref().unwrap();
|
let tile = tile_attributes.as_ref().unwrap();
|
||||||
if chunk_offsets.len() != chunk_bytes.len()
|
|
||||||
|| chunk_offsets.len()
|
if chunk_offsets.len() != chunk_bytes.len() {
|
||||||
!= tile.tiles_down() * tile.tiles_across() * planes as usize
|
|
||||||
{
|
|
||||||
return Err(TiffError::FormatError(
|
return Err(TiffError::FormatError(
|
||||||
TiffFormatError::InconsistentSizesEncountered,
|
TiffFormatError::InconsistentSizesEncountered,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if chunk_offsets.len() != tile.tiles_down() * tile.tiles_across() * planes as usize
|
||||||
|
{
|
||||||
|
return Err(TiffError::FormatError(
|
||||||
|
TiffFormatError::IncorrectChunkCount {
|
||||||
|
expected: (tile.tiles_down() * tile.tiles_across() * planes as usize)
|
||||||
|
as u32,
|
||||||
|
found: chunk_offsets.len() as u32,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(_, _, _, _) => {
|
(_, _, _, _) => {
|
||||||
return Err(TiffError::FormatError(
|
return Err(TiffError::FormatError(
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ quick_error! {
|
|||||||
InconsistentSizesEncountered {
|
InconsistentSizesEncountered {
|
||||||
display("inconsistent sizes encountered")
|
display("inconsistent sizes encountered")
|
||||||
}
|
}
|
||||||
|
IncorrectChunkCount {expected: u32, found: u32} {
|
||||||
|
display("incorrect number of chunk offsets encoded for the tile count of the image, expected {expected} but found {found}")
|
||||||
|
}
|
||||||
InvalidDimensions(width: u32, height: u32) {
|
InvalidDimensions(width: u32, height: u32) {
|
||||||
display("invalid dimensions: {width}x{height}")
|
display("invalid dimensions: {width}x{height}")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user