Browse Source

LibGfx/JPEG2000: Check SIZ marker (w, h) against JP2 header (w, h)

Nico Weber 1 year ago
parent
commit
1a232ba2a6
1 changed files with 7 additions and 0 deletions
  1. 7 0
      Userland/Libraries/LibGfx/ImageFormats/JPEG2000Loader.cpp

+ 7 - 0
Userland/Libraries/LibGfx/ImageFormats/JPEG2000Loader.cpp

@@ -801,6 +801,13 @@ static ErrorOr<void> decode_jpeg2000_header(JPEG2000LoadingContext& context, Rea
 
     TRY(parse_codestream_main_header(context));
 
+    auto size_from_siz = IntSize { context.siz.width, context.siz.height };
+    if (size_from_siz != context.size) {
+        // FIXME: If this is common, warn and use size from SIZ marker.
+        dbgln("JPEG2000ImageDecoderPlugin: Image size from SIZ marker ({}) does not match image size from JP2 header ({})", size_from_siz, context.size);
+        return Error::from_string_literal("JPEG2000ImageDecoderPlugin: Image size from SIZ marker does not match image size from JP2 header");
+    }
+
     return {};
 }