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

93cbb4
From a7b920bdbde1ee15a1a470d743dbae69ee398c75 Mon Sep 17 00:00:00 2001
93cbb4
From: Kevin Backhouse <kevinbackhouse@github.com>
93cbb4
Date: Wed, 30 Jun 2021 16:47:12 +0100
93cbb4
Subject: [PATCH 1/2] Regression test for
93cbb4
 https://github.com/Exiv2/exiv2/security/advisories/GHSA-mxw9-qx4c-6m8v
93cbb4
93cbb4
---
93cbb4
 test/data/issue_ghsa_mxw9_qx4c_6m8v_poc.jp2   | Bin 0 -> 1692 bytes
93cbb4
 .../github/test_issue_ghsa_mxw9_qx4c_6m8v.py  |  18 ++++++++++++++++++
93cbb4
 2 files changed, 18 insertions(+)
93cbb4
 create mode 100644 test/data/issue_ghsa_mxw9_qx4c_6m8v_poc.jp2
93cbb4
 create mode 100644 tests/bugfixes/github/test_issue_ghsa_mxw9_qx4c_6m8v.py
93cbb4
93cbb4
diff --git a/tests/bugfixes/github/test_issue_ghsa_mxw9_qx4c_6m8v.py b/tests/bugfixes/github/test_issue_ghsa_mxw9_qx4c_6m8v.py
93cbb4
new file mode 100644
93cbb4
index 0000000000..8f8b6676cf
93cbb4
--- /dev/null
93cbb4
+++ b/tests/bugfixes/github/test_issue_ghsa_mxw9_qx4c_6m8v.py
93cbb4
@@ -0,0 +1,18 @@
93cbb4
+# -*- coding: utf-8 -*-
93cbb4
+
93cbb4
+from system_tests import CaseMeta, CopyTmpFiles, path, check_no_ASAN_UBSAN_errors
93cbb4
+@CopyTmpFiles("$data_path/issue_ghsa_mxw9_qx4c_6m8v_poc.jp2")
93cbb4
+
93cbb4
+class Jp2ImageEncodeJp2HeaderOutOfBoundsRead2(metaclass=CaseMeta):
93cbb4
+    """
93cbb4
+    Regression test for the bug described in:
93cbb4
+    https://github.com/Exiv2/exiv2/security/advisories/GHSA-mxw9-qx4c-6m8v
93cbb4
+    """
93cbb4
+    url = "https://github.com/Exiv2/exiv2/security/advisories/GHSA-mxw9-qx4c-6m8v"
93cbb4
+
93cbb4
+    filename = path("$tmp_path/issue_ghsa_mxw9_qx4c_6m8v_poc.jp2")
93cbb4
+    commands = ["$exiv2 rm $filename"]
93cbb4
+    stdout = [""]
93cbb4
+    retval = [0]
93cbb4
+
93cbb4
+    compare_stderr = check_no_ASAN_UBSAN_errors
93cbb4
c13fd3
From 9be257340193dbe3fb810aa33531c40ae9df6414 Mon Sep 17 00:00:00 2001
c13fd3
From: Kevin Backhouse <kevinbackhouse@github.com>
c13fd3
Date: Wed, 30 Jun 2021 16:47:50 +0100
c13fd3
Subject: [PATCH 2/2] Fix incorrect loop condition.
c13fd3
c13fd3
---
c13fd3
 src/jp2image.cpp                                      |  6 ++++--
c13fd3
 .../bugfixes/github/test_issue_ghsa_8949_hhfh_j7rj.py | 11 +++++------
c13fd3
 2 files changed, 9 insertions(+), 8 deletions(-)
c13fd3
c13fd3
diff --git a/src/jp2image.cpp b/src/jp2image.cpp
c13fd3
index b6a388542f..3bf3566294 100644
c13fd3
--- a/src/jp2image.cpp
c13fd3
+++ b/src/jp2image.cpp
c13fd3
@@ -656,12 +656,14 @@ static void boxes_check(size_t b,size_t m)
c13fd3
         char*         p      = (char*) boxBuf.pData_;
c13fd3
         bool          bWroteColor = false ;
c13fd3
c13fd3
-        while ( count < length || !bWroteColor ) {
c13fd3
+        while ( count < length && !bWroteColor ) {
c13fd3
             enforce(sizeof(Jp2BoxHeader) <= length - count, Exiv2::kerCorruptedMetadata);
c13fd3
             Jp2BoxHeader* pSubBox = (Jp2BoxHeader*) (p+count) ;
c13fd3
c13fd3
             // copy data.  pointer could be into a memory mapped file which we will decode!
c13fd3
-            Jp2BoxHeader   subBox = *pSubBox ;
c13fd3
+            // pSubBox isn't always an aligned pointer, so use memcpy to do the copy.
c13fd3
+            Jp2BoxHeader   subBox;
c13fd3
+            memcpy(&subBox, pSubBox, sizeof(Jp2BoxHeader));
c13fd3
             Jp2BoxHeader   newBox =  subBox;
c13fd3
c13fd3
             if ( count < length ) {
c13fd3
diff --git a/tests/bugfixes/github/test_issue_ghsa_8949_hhfh_j7rj.py b/tests/bugfixes/github/test_issue_ghsa_8949_hhfh_j7rj.py
c13fd3
index c98b3815eb..44f6a906cb 100644
c13fd3
--- a/tests/bugfixes/github/test_issue_ghsa_8949_hhfh_j7rj.py
c13fd3
+++ b/tests/bugfixes/github/test_issue_ghsa_8949_hhfh_j7rj.py
c13fd3
@@ -1,7 +1,7 @@
c13fd3
 # -*- coding: utf-8 -*-
c13fd3
c13fd3
-from system_tests import CaseMeta, path
c13fd3
-
c13fd3
+from system_tests import CaseMeta, CopyTmpFiles, path
c13fd3
+@CopyTmpFiles("$data_path/issue_ghsa_8949_hhfh_j7rj_poc.jp2","$data_path/issue_ghsa_8949_hhfh_j7rj_poc.exv")
c13fd3
c13fd3
 class Jp2ImageEncodeJp2HeaderOutOfBoundsRead(metaclass=CaseMeta):
c13fd3
     """
c13fd3
@@ -10,13 +10,12 @@ class Jp2ImageEncodeJp2HeaderOutOfBoundsRead(metaclass=CaseMeta):
c13fd3
     """
c13fd3
     url = "https://github.com/Exiv2/exiv2/security/advisories/GHSA-8949-hhfh-j7rj"
c13fd3
c13fd3
-    filename1 = path("$data_path/issue_ghsa_8949_hhfh_j7rj_poc.jp2")
c13fd3
-    filename2 = path("$data_path/issue_ghsa_8949_hhfh_j7rj_poc.exv")
c13fd3
+    filename1 = path("$tmp_path/issue_ghsa_8949_hhfh_j7rj_poc.jp2")
c13fd3
+    filename2 = path("$tmp_path/issue_ghsa_8949_hhfh_j7rj_poc.exv")
c13fd3
     commands = ["$exiv2 in $filename1"]
c13fd3
     stdout = [""]
c13fd3
     stderr = [
c13fd3
 """Error: XMP Toolkit error 201: XML parsing failure
c13fd3
 Warning: Failed to decode XMP metadata.
c13fd3
-$filename1: Could not write metadata to file: $kerCorruptedMetadata
c13fd3
 """]
c13fd3
-    retval = [1]
c13fd3
+    retval = [0]