diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index ffd47e6a3e..6c475bf8ca 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -254,6 +254,17 @@ TEST_CASE(test_brush_transparent_color) EXPECT_EQ(frame.image->get_pixel(114, 103), Gfx::Color::NamedColor::Black); } +TEST_CASE(test_small_24bit) +{ + auto file = MUST(Core::MappedFile::map(TEST_INPUT("ilbm/small-24bit.iff"sv))); + EXPECT(Gfx::ILBMImageDecoderPlugin::sniff(file->bytes())); + auto plugin_decoder = TRY_OR_FAIL(Gfx::ILBMImageDecoderPlugin::create(file->bytes())); + + auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 10, 10 })); + + EXPECT_EQ(frame.image->get_pixel(0, 4), Gfx::Color(1, 0, 1, 255)); +} + TEST_CASE(test_ilbm_malformed_header) { Array test_inputs = { diff --git a/Tests/LibGfx/test-inputs/ilbm/small-24bit.iff b/Tests/LibGfx/test-inputs/ilbm/small-24bit.iff new file mode 100644 index 0000000000..39580314bc Binary files /dev/null and b/Tests/LibGfx/test-inputs/ilbm/small-24bit.iff differ diff --git a/Userland/Libraries/LibGfx/ImageFormats/ILBMLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/ILBMLoader.cpp index e89f6bff24..1b10f91978 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/ILBMLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/ILBMLoader.cpp @@ -220,7 +220,9 @@ static ErrorOr planar_to_chunky(ReadonlyBytes bitplanes, ILBMLoading u8 bit = bitplanes[offset_base + i]; u8 rgb_shift = p / 8; - for (u8 b = 0; b < 8; b++) { + // Some encoders don't pad bytes rows with 0: make sure we stop + // when enough data for current bitplane row has been read + for (u8 b = 0; b < 8 && (i * 8) + b < width; b++) { u8 mask = 1 << (7 - b); // get current plane if (bit & mask) {