Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exif,tiff: Handle broken last next ifd offset by treating it as end m… #804

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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