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

93cbb4
From f13ebca839e55d0c7ea1c7f57ae667c47fe9c0d5 Mon Sep 17 00:00:00 2001
93cbb4
From: Kevin Backhouse <kevinbackhouse@github.com>
93cbb4
Date: Mon, 5 Jul 2021 10:39:08 +0100
93cbb4
Subject: [PATCH 1/2] Regression test for
93cbb4
 https://github.com/Exiv2/exiv2/security/advisories/GHSA-583f-w9pm-99r2
93cbb4
93cbb4
---
93cbb4
 test/data/issue_ghsa_583f_w9pm_99r2_poc.jp2   | Bin 0 -> 32768 bytes
93cbb4
 .../github/test_issue_ghsa_583f_w9pm_99r2.py  |  18 ++++++++++++++++++
93cbb4
 2 files changed, 18 insertions(+)
93cbb4
 create mode 100644 test/data/issue_ghsa_583f_w9pm_99r2_poc.jp2
93cbb4
 create mode 100644 tests/bugfixes/github/test_issue_ghsa_583f_w9pm_99r2.py
93cbb4
93cbb4
diff --git a/tests/bugfixes/github/test_issue_ghsa_583f_w9pm_99r2.py b/tests/bugfixes/github/test_issue_ghsa_583f_w9pm_99r2.py
93cbb4
new file mode 100644
93cbb4
index 000000000..808916aee
93cbb4
--- /dev/null
93cbb4
+++ b/tests/bugfixes/github/test_issue_ghsa_583f_w9pm_99r2.py
93cbb4
@@ -0,0 +1,18 @@
93cbb4
+# -*- coding: utf-8 -*-
93cbb4
+
93cbb4
+from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
93cbb4
+
93cbb4
+class Jp2ImagePrintStructureICC(metaclass=CaseMeta):
93cbb4
+    """
93cbb4
+    Regression test for the bug described in:
93cbb4
+    https://github.com/Exiv2/exiv2/security/advisories/GHSA-583f-w9pm-99r2
93cbb4
+    """
93cbb4
+    url = "https://github.com/Exiv2/exiv2/security/advisories/GHSA-583f-w9pm-99r2"
93cbb4
+
93cbb4
+    filename = path("$data_path/issue_ghsa_583f_w9pm_99r2_poc.jp2")
93cbb4
+    commands = ["$exiv2 -p C $filename"]
93cbb4
+    stdout = [""]
93cbb4
+    stderr = ["""Exiv2 exception in print action for file $filename:
93cbb4
+$kerCorruptedMetadata
93cbb4
+"""]
93cbb4
+    retval = [1]
93cbb4
c13fd3
From dbf472751fc8b87ea7d1de02f54eaf64233a2fb6 Mon Sep 17 00:00:00 2001
c13fd3
From: Kevin Backhouse <kevinbackhouse@github.com>
c13fd3
Date: Mon, 5 Jul 2021 10:40:03 +0100
c13fd3
Subject: [PATCH 2/2] Better bounds checking in Jp2Image::printStructure
c13fd3
c13fd3
---
c13fd3
 src/jp2image.cpp | 2 ++
c13fd3
 1 file changed, 2 insertions(+)
c13fd3
c13fd3
diff --git a/src/jp2image.cpp b/src/jp2image.cpp
c13fd3
index 3bf356629..2d6dc2118 100644
c13fd3
--- a/src/jp2image.cpp
c13fd3
+++ b/src/jp2image.cpp
c13fd3
@@ -538,6 +538,7 @@ static void boxes_check(size_t b,size_t m)
c13fd3
c13fd3
                             if (subBox.type == kJp2BoxTypeColorHeader) {
c13fd3
                                 long pad = 3;  // don't know why there are 3 padding bytes
c13fd3
+                                enforce(data.size_ >= pad, kerCorruptedMetadata);
c13fd3
                                 if (bPrint) {
c13fd3
                                     out << " | pad:";
c13fd3
                                     for (int i = 0; i < 3; i++)
c13fd3
@@ -547,6 +548,7 @@ static void boxes_check(size_t b,size_t m)
c13fd3
                                 if (bPrint) {
c13fd3
                                     out << " | iccLength:" << iccLength;
c13fd3
                                 }
c13fd3
+                                enforce(iccLength <= data.size_ - pad, kerCorruptedMetadata);
c13fd3
                                 if (bICC) {
c13fd3
                                     out.write((const char*)data.pData_ + pad, iccLength);
c13fd3
                                 }