Skip to content

Commit

Permalink
LibGfx/TIFF: Prevent recursion when following IFD pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasChollet authored and awesomekling committed Apr 7, 2024
1 parent 2c86633 commit cb5f30a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,24 @@ class TIFFLoadingContext {
VERIFY_NOT_REACHED();
}

ErrorOr<void> set_next_ifd(u32 ifd_offset)
{
if (ifd_offset != 0) {
if (ifd_offset < TRY(m_stream->tell()))
return Error::from_string_literal("TIFFImageDecoderPlugin: Can not accept an IFD pointing to previous data");

m_next_ifd = Optional<u32> { ifd_offset };
} else {
m_next_ifd = OptionalNone {};
}
return {};
}

ErrorOr<void> read_next_idf_offset()
{
auto const next_block_position = TRY(read_value<u32>());
TRY(set_next_ifd(next_block_position));

if (next_block_position != 0)
m_next_ifd = Optional<u32> { next_block_position };
else
m_next_ifd = OptionalNone {};
return {};
}

Expand Down Expand Up @@ -684,7 +694,10 @@ class TIFFLoadingContext {
}()));

auto subifd_handler = [&](u32 ifd_offset) -> ErrorOr<void> {
m_next_ifd = ifd_offset;
if (auto result = set_next_ifd(ifd_offset); result.is_error()) {
dbgln("{}", result.error());
return {};
}
TRY(read_next_image_file_directory());
return {};
};
Expand Down

0 comments on commit cb5f30a

Please sign in to comment.