cc9aa80
From 13e5a3e02339b746abcaee6408893ca2fd8e289d Mon Sep 17 00:00:00 2001
cc9aa80
From: Pydera <pydera@mailbox.org>
cc9aa80
Date: Thu, 8 Apr 2021 17:36:16 +0200
cc9aa80
Subject: [PATCH] Fix out of buffer access in #1529
cc9aa80
cc9aa80
---
cc9aa80
 src/jp2image.cpp | 5 +++--
cc9aa80
 1 file changed, 3 insertions(+), 2 deletions(-)
cc9aa80
cc9aa80
diff --git a/src/jp2image.cpp b/src/jp2image.cpp
cc9aa80
index 88ab9b2d6..12025f966 100644
cc9aa80
--- a/src/jp2image.cpp
cc9aa80
+++ b/src/jp2image.cpp
cc9aa80
@@ -776,9 +776,10 @@ static void boxes_check(size_t b,size_t m)
cc9aa80
 #endif
cc9aa80
                 box.length = (uint32_t) (io_->size() - io_->tell() + 8);
cc9aa80
             }
cc9aa80
-            if (box.length == 1)
cc9aa80
+            if (box.length < 8)
cc9aa80
             {
cc9aa80
-                // FIXME. Special case. the real box size is given in another place.
cc9aa80
+                // box is broken, so there is nothing we can do here
cc9aa80
+                throw Error(kerCorruptedMetadata);
cc9aa80
             }
cc9aa80
cc9aa80
             // Read whole box : Box header + Box data (not fixed size - can be null).