mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:47:35 +00:00
LibGfx/TIFF: Don't stop decoding when failing to decode a tag
TIFF files are made in a way that make them easily extendable and over the years people have made sure to exploit that. In other words, it's easy to find images with non-standard tags. Instead of returning an error for that, let's skip them. Note that we need to make sure to realign the reading head in the file. The test case was originally a 10x10 checkerboard image with required tags, and also the `DocumentName` tag. Then, I modified this tag in a hexadecimal editor and replaced its id with 30 000 (0x3075 as a LE u16) and the type with the same value as well. This is AFAIK, never used as a custom TIFF tag, so this should remain an invalid tag id and type.
This commit is contained in:
parent
6d1c10ed10
commit
b8cbc282f3
3 changed files with 23 additions and 2 deletions
|
@ -387,9 +387,18 @@ private:
|
|||
TRY(m_stream->seek(m_next_ifd.value()));
|
||||
|
||||
auto const number_of_field = TRY(read_value<u16>());
|
||||
auto next_tag_offset = TRY(m_stream->tell());
|
||||
|
||||
for (u16 i = 0; i < number_of_field; ++i)
|
||||
TRY(read_tag());
|
||||
for (u16 i = 0; i < number_of_field; ++i) {
|
||||
TRY(m_stream->seek(next_tag_offset));
|
||||
if (auto maybe_error = read_tag(); maybe_error.is_error() && TIFF_DEBUG)
|
||||
dbgln("Unable to decode tag {}/{}", i + 1, number_of_field);
|
||||
|
||||
// Section 2: TIFF Structure
|
||||
// IFD Entry
|
||||
// Size of tag(u16) + type(u16) + count(u32) + value_or_offset(u32) = 12
|
||||
next_tag_offset += 12;
|
||||
}
|
||||
|
||||
TRY(read_next_idf_offset());
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue