Blame SOURCES/exiv2-CVE-2021-29470.patch

8ca4c1
diff --git a/src/jp2image.cpp b/src/jp2image.cpp
8ca4c1
index 0de088d..6310c08 100644
8ca4c1
--- a/src/jp2image.cpp
8ca4c1
+++ b/src/jp2image.cpp
8ca4c1
@@ -645,13 +645,16 @@ static void boxes_check(size_t b,size_t m)
8ca4c1
         DataBuf output(boxBuf.size_ + iccProfile_.size_ + 100); // allocate sufficient space
8ca4c1
         int     outlen = sizeof(Jp2BoxHeader) ; // now many bytes have we written to output?
8ca4c1
         int      inlen = sizeof(Jp2BoxHeader) ; // how many bytes have we read from boxBuf?
8ca4c1
+        enforce(sizeof(Jp2BoxHeader) <= static_cast<size_t>(output.size_), Exiv2::kerCorruptedMetadata);
8ca4c1
         Jp2BoxHeader* pBox   = (Jp2BoxHeader*) boxBuf.pData_;
8ca4c1
         int32_t       length = getLong((byte*)&pBox->length, bigEndian);
8ca4c1
+        enforce(length <= static_cast<size_t>(output.size_), Exiv2::kerCorruptedMetadata);
8ca4c1
         int32_t       count  = sizeof (Jp2BoxHeader);
8ca4c1
         char*         p      = (char*) boxBuf.pData_;
8ca4c1
         bool          bWroteColor = false ;
8ca4c1
 
8ca4c1
         while ( count < length || !bWroteColor ) {
8ca4c1
+            enforce(sizeof(Jp2BoxHeader) <= length - count, Exiv2::kerCorruptedMetadata);
8ca4c1
             Jp2BoxHeader* pSubBox = (Jp2BoxHeader*) (p+count) ;
8ca4c1
 
8ca4c1
             // copy data.  pointer could be into a memory mapped file which we will decode!