diff --git a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp index 342037079c..b00b63c746 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp @@ -561,9 +561,12 @@ static ErrorOr decode_end_of_stripe(JBIG2LoadingContext&, SegmentData cons return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode end of stripe yet"); } -static ErrorOr decode_end_of_file(JBIG2LoadingContext&, SegmentData const&) +static ErrorOr decode_end_of_file(JBIG2LoadingContext&, SegmentData const& segment) { - return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode end of file yet"); + // 7.4.11 End of file segment syntax + if (segment.data.size() != 0) + return Error::from_string_literal("JBIG2ImageDecoderPlugin: End of file segment has non-zero size"); + return {}; } static ErrorOr decode_profiles(JBIG2LoadingContext&, SegmentData const&) @@ -649,7 +652,9 @@ static ErrorOr decode_data(JBIG2LoadingContext& context) { TRY(warn_about_multiple_pages(context)); - for (auto const& segment : context.segments) { + for (size_t i = 0; i < context.segments.size(); ++i) { + auto const& segment = context.segments[i]; + if (segment.header.page_association != 0 && segment.header.page_association != 1) continue; @@ -707,6 +712,9 @@ static ErrorOr decode_data(JBIG2LoadingContext& context) break; case SegmentType::EndOfFile: TRY(decode_end_of_file(context, segment)); + // "If a file contains an end of file segment, it must be the last segment." + if (i != context.segments.size() - 1) + return Error::from_string_literal("JBIG2ImageDecoderPlugin: End of file segment not last segment"); break; case SegmentType::Profiles: TRY(decode_profiles(context, segment));