diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index e75f0c8fa42..ce1ae607ca9 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -134,6 +134,17 @@ TEST_CASE(test_jpeg_sof2_spectral_selection) EXPECT_EQ(frame.image->size(), Gfx::IntSize(592, 800)); } +TEST_CASE(test_jpeg_sof0_several_scans_odd_number_mcu) +{ + auto file = MUST(Core::MappedFile::map(TEST_INPUT("several_scans_odd_number_mcu.jpg"sv))); + EXPECT(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes())); + auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); + EXPECT(plugin_decoder->initialize()); + + auto frame = MUST(plugin_decoder->frame(0)); + EXPECT_EQ(frame.image->size(), Gfx::IntSize(600, 600)); +} + TEST_CASE(test_pbm) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie-raw.pbm"sv))); diff --git a/Tests/LibGfx/test-inputs/several_scans_odd_number_mcu.jpg b/Tests/LibGfx/test-inputs/several_scans_odd_number_mcu.jpg new file mode 100644 index 00000000000..2e775e6b1c5 Binary files /dev/null and b/Tests/LibGfx/test-inputs/several_scans_odd_number_mcu.jpg differ diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp index 24ff7737100..c6f6a628e2c 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp @@ -446,9 +446,21 @@ static ErrorOr build_macroblocks(JPEGLoadingContext& context, Vector= context.mblock_meta.hcount && macroblock_index % context.mblock_meta.hpadded_count >= context.mblock_meta.hcount) + continue; + // Vertically + if (macroblock_index >= context.mblock_meta.hpadded_count * context.mblock_meta.vcount) + continue; + } + // G.1.2.2 - Progressive encoding of AC coefficients with Huffman coding if (context.current_scan.end_of_bands_run_count > 0) { --context.current_scan.end_of_bands_run_count;