From af20ebe4a06ef52f230c4255254d0097f8bb005c Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 7 Mar 2024 20:13:58 -0500 Subject: [PATCH] LibGfx/JBIG2: Scan for page size of page "1" Sounds like the spec guarantees that that's the number of the first page. (In practice, all but one of all jbig2 files I've found contain just page 1. PDFs almost always contain just page 1, and very rarely a page 0 for globally shared parameters.) --- Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp index 72e1157e91..ee2638373c 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp @@ -58,7 +58,11 @@ struct SegmentHeader { u32 segment_number; SegmentType type; Vector referred_to_segment_numbers; + + // 7.2.6 Segment page association + // "The first page must be numbered "1". This field may contain a value of zero; this value indicates that this segment is not associated with any page." u32 page_association; + Optional data_length; }; @@ -289,13 +293,13 @@ static ErrorOr scan_for_page_size(JBIG2LoadingContext& context) { // We only decode the first page at the moment. for (auto const& segment : context.segments) { - if (segment.header.type != SegmentType::PageInformation) + if (segment.header.type != SegmentType::PageInformation || segment.header.page_association != 1) continue; auto page_information = TRY(decode_page_information_segment(segment.data)); context.size = { page_information.bitmap_width, page_information.bitmap_height }; return {}; } - return Error::from_string_literal("JBIG2ImageDecoderPlugin: No page information segment found"); + return Error::from_string_literal("JBIG2ImageDecoderPlugin: No page information segment found for page 1"); } JBIG2ImageDecoderPlugin::JBIG2ImageDecoderPlugin()