LibGfx: Allow decoding of GIFs with empty LZW data

The decoder was requiring GIF files to be at least 32 bytes, but the
actual minimum for a valid GIF is only 26 bytes:
- 6 bytes for the header
- 7 bytes for the Logical Screen Descriptor
- 10 bytes for the Image Descriptor
- 2 bytes for the LZW minimum code size and block terminator
- 1 byte for the GIF trailer

This change allows us to load minimal 1x1 GIFs with empty LZW data.
They are commonly used on the web as transparent placeholders with
minimal file size.
This commit is contained in:
aplefull 2025-10-01 14:35:07 +02:00 committed by Jelle Raaijmakers
parent 30d4810d70
commit b3bdb202f8
Notes: github-actions[bot] 2025-10-02 09:05:55 +00:00
3 changed files with 17 additions and 3 deletions

View file

@ -215,6 +215,17 @@ TEST_CASE(test_gif_without_global_color_table)
EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::Red);
}
TEST_CASE(test_gif_empty_lzw_data)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("gif/minimal-1x1.gif"sv)));
EXPECT(Gfx::GIFImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::GIFImageDecoderPlugin::create(file->bytes()));
EXPECT_EQ(plugin_decoder->frame_count(), 1u);
auto frame = TRY_OR_FAIL(plugin_decoder->frame(0));
EXPECT_EQ(frame.image->size(), Gfx::IntSize(1, 1));
}
TEST_CASE(test_not_ico)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("png/buggie.png"sv)));

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 B