Skip to content

Commit

Permalink
Merge pull request #804 from wader/exif-broken-next-ifd-offset
Browse files Browse the repository at this point in the history
exif,tiff: Handle broken last next ifd offset by treating it as end m…
  • Loading branch information
wader authored Nov 3, 2023
2 parents 80bfbb4 + 02b3527 commit 1fb2054
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions format/riff/testdata/xmp_exif.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ $ fq -d webp dv xmp_exif.webp
0x0f0| 05 00 00 00 | .... | value_offset: 83886080 0xfa-0xfe (4)
| | | values[0:1]: 0xfa-0xfc (2)
0x0f0| 05 00 | .. | [0]: 1280 value 0xfa-0xfc (2)
0x0f0| 00 00| ..| next_ifd: 0 0xfe-0x102 (4)
0x0f0| 00 00| ..| next_ifd: 0x0 0xfe-0x102 (4)
0x100|00 00 |.. |
0x0a0|00 00 00 00 |.... | next_ifd: 0 0xa0-0xa4 (4)
0x0a0|00 00 00 00 |.... | next_ifd: 0x0 0xa0-0xa4 (4)
| | | [3]{}: chunk 0x102-0xd02 (3072)
0x100| 58 4d 50 20 | XMP | id: "XMP " 0x102-0x106 (4)
0x100| f7 0b 00 00 | .... | size: 3063 0x106-0x10a (4)
Expand Down
2 changes: 1 addition & 1 deletion format/tiff/testdata/4x4.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ $ fq -d tiff dv 4x4.tiff
0x0b0| 01 00 00 00 | .... | value_offset: 1 0xb2-0xb6 (4)
| | | values[0:1]: 0xb2-0xb4 (2)
0x0b0| 01 00 | .. | [0]: 1 value 0xb2-0xb4 (2)
0x0b0| 00 00 00 00 | .... | next_ifd: 0 0xb6-0xba (4)
0x0b0| 00 00 00 00 | .... | next_ifd: 0x0 0xb6-0xba (4)
0x0c0| 00 | . | gap0: raw bits 0xc3-0xc4 (1)
5 changes: 3 additions & 2 deletions format/tiff/tiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func decodeIfd(d *decode.D, s *strips, tagNames scalar.UintMapSymStr) int64 {
}
})

nextIfdOffset = int64(d.FieldU32("next_ifd"))
nextIfdOffset = int64(d.FieldU32("next_ifd", scalar.UintHex))
})

return nextIfdOffset
Expand Down Expand Up @@ -226,7 +226,8 @@ func tiffDecode(d *decode.D) any {
ifdSeen := map[int64]struct{}{}

d.FieldArray("ifds", func(d *decode.D) {
for ifdOffset != 0 {
// sanity check offset
for ifdOffset > 0 && ifdOffset*8 < d.Len() {
if _, ok := ifdSeen[ifdOffset]; ok {
d.Fatalf("ifd loop detected for %d", ifdOffset)
}
Expand Down

0 comments on commit 1fb2054

Please sign in to comment.