mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 15:55:14 +00:00
image-codecs: skip a SubIFDs array whose offset is cut off (#1889)
camera_raw_mode read a missing SubIFDs offset as 0, so it walked the TIFF header as the pointer array and could classify a malformed TIFF as RAW. Skip the entry instead, matching LightCraft's classifier.
This commit is contained in:
1 parent
d60d1b0a45
commit
a58989cae9
2 files changed
+24
-2
No files matched your search
@@ -207,8 +207,10 @@ fn camera_raw_mode(b: &[u8], legacy: bool) -> bool {
|
||||
}
|
||||
TAG_SUB_IFDS if count == 1 => queue.extend(value(e)),
|
||||
TAG_SUB_IFDS => {
|
||||
// More than one offset: they are stored at the entry's offset.
|
||||
let at = u32_at(e.saturating_add(8)).unwrap_or(0) as usize;
|
||||
// More than one offset: they are stored at the entry's offset. A cut-off
|
||||
// offset field means no array, not one at the start of the file.
|
||||
let Some(at) = u32_at(e.saturating_add(8)) else { continue };
|
||||
let at = at as usize;
|
||||
for k in 0..count.min(8) as usize {
|
||||
queue.extend(u32_at(at.saturating_add(4 * k)));
|
||||
}
|
||||
|
||||
@@ -63,3 +63,23 @@ fn oversized_or_cut_directories_are_skipped() {
|
||||
cut.truncate(20);
|
||||
assert!(!legacy_tiff_raw_hint(&cut));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_subifds_array_without_its_offset_is_skipped() {
|
||||
// IFD0 at 64 holds one SubIFDs entry (LONG, count 3) whose offset field is cut off. A DNG
|
||||
// directory sits at 32, and the bytes at 8 point to it. Reading the missing offset as 0
|
||||
// would treat the TIFF header as the pointer array and follow 8 -> 32.
|
||||
let mut b = vec![0u8; 64];
|
||||
b[..8].copy_from_slice(b"II\x2a\0\x40\0\0\0");
|
||||
b[8..12].copy_from_slice(&32u32.to_le_bytes());
|
||||
b[32..34].copy_from_slice(&1u16.to_le_bytes());
|
||||
b[34..46].copy_from_slice(&[0x12, 0xc6, 1, 0, 4, 0, 0, 0, 1, 4, 0, 0]);
|
||||
b.extend_from_slice(&1u16.to_le_bytes());
|
||||
b.extend_from_slice(&[0x4a, 0x01, 4, 0, 3, 0, 0, 0]);
|
||||
assert_eq!(b.len(), 74);
|
||||
assert!(!legacy_tiff_raw_hint(&b));
|
||||
// With the offset present (the array at 8), the same SubIFD is followed.
|
||||
let mut whole = b.clone();
|
||||
whole.extend_from_slice(&8u32.to_le_bytes());
|
||||
assert!(legacy_tiff_raw_hint(&whole));
|
||||
}
|
||||
Reference in new issue
Block a user