3587f3
From 89a5367d49b2556a2635dbb6d48d6a6b182a2c6c Mon Sep 17 00:00:00 2001
3587f3
From: Albert Astals Cid <aacid@kde.org>
3587f3
Date: Thu, 23 May 2019 00:54:29 +0200
3587f3
Subject: [PATCH] JPEG2000Stream: fail gracefully if not all components have
3587f3
 the same WxH
3587f3
3587f3
I think this is just a mistake, or at least the only file we have with
3587f3
this scenario is a fuzzed one
3587f3
---
3587f3
 poppler/JPEG2000Stream.cc | 8 +++++++-
3587f3
 1 file changed, 7 insertions(+), 1 deletion(-)
3587f3
3587f3
diff --git a/poppler/JPEG2000Stream.cc b/poppler/JPEG2000Stream.cc
3587f3
index 15bbcae4..0eea3a2d 100644
3587f3
--- a/poppler/JPEG2000Stream.cc
3587f3
+++ b/poppler/JPEG2000Stream.cc
3587f3
@@ -4,7 +4,7 @@
3587f3
 //
3587f3
 // A JPX stream decoder using OpenJPEG
3587f3
 //
3587f3
-// Copyright 2008-2010, 2012, 2017, 2018 Albert Astals Cid <aacid@kde.org>
3587f3
+// Copyright 2008-2010, 2012, 2017-2019 Albert Astals Cid <aacid@kde.org>
3587f3
 // Copyright 2011 Daniel Glöckner <daniel-gl@gmx.net>
3587f3
 // Copyright 2014, 2016 Thomas Freitag <Thomas.Freitag@alfa.de>
3587f3
 // Copyright 2013, 2014 Adrian Johnson <ajohnson@redneon.com>
3587f3
@@ -253,6 +253,12 @@ void JPXStream::init()
3587f3
         close();
3587f3
         break;
3587f3
       }
3587f3
+      const int componentPixels = priv->image->comps[component].w * priv->image->comps[component].h;
3587f3
+      if (componentPixels != priv->npixels) {
3587f3
+        error(errSyntaxWarning, -1, "Component {0:d} has different WxH than component 0", component);
3587f3
+        close();
3587f3
+        break;
3587f3
+      }
3587f3
       unsigned char *cdata = (unsigned char *)priv->image->comps[component].data;
3587f3
       int adjust = 0;
3587f3
       int depth = priv->image->comps[component].prec;
3587f3
-- 
3587f3
2.21.0
3587f3