Blame SOURCES/0024-CVE-2022-0865-tif_jbig.c-fix-crash-when-reading-a-fi.patch

12208d
From 2d598cd7523cba7ee8441fac96bfe422ec277efc Mon Sep 17 00:00:00 2001
12208d
From: Even Rouault <even.rouault@spatialys.com>
12208d
Date: Thu, 24 Feb 2022 22:26:02 +0100
12208d
Subject: [PATCH] (CVE-2022-0865) tif_jbig.c: fix crash when reading a file
12208d
 with multiple IFD in memory-mapped mode and when bit reversal is needed
12208d
 (fixes #385)
12208d
12208d
(cherry picked from commit a1c933dabd0e1c54a412f3f84ae0aa58115c6067)
12208d
---
12208d
 libtiff/tif_jbig.c | 10 ++++++++++
12208d
 1 file changed, 10 insertions(+)
12208d
12208d
diff --git a/libtiff/tif_jbig.c b/libtiff/tif_jbig.c
12208d
index 8136c77b..698428f0 100644
12208d
--- a/libtiff/tif_jbig.c
12208d
+++ b/libtiff/tif_jbig.c
12208d
@@ -210,6 +210,16 @@ int TIFFInitJBIG(TIFF* tif, int scheme)
12208d
 	 */
12208d
 	tif->tif_flags |= TIFF_NOBITREV;
12208d
 	tif->tif_flags &= ~TIFF_MAPPED;
12208d
+	/* We may have read from a previous IFD and thus set TIFF_BUFFERMMAP and
12208d
+	 * cleared TIFF_MYBUFFER. It is necessary to restore them to their initial
12208d
+	 * value to be consistent with the state of a non-memory mapped file.
12208d
+	 */
12208d
+	if (tif->tif_flags&TIFF_BUFFERMMAP) {
12208d
+		tif->tif_rawdata = NULL;
12208d
+		tif->tif_rawdatasize = 0;
12208d
+		tif->tif_flags &= ~TIFF_BUFFERMMAP;
12208d
+		tif->tif_flags |= TIFF_MYBUFFER;
12208d
+	}
12208d
 
12208d
 	/* Setup the function pointers for encode, decode, and cleanup. */
12208d
 	tif->tif_setupdecode = JBIGSetupDecode;