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

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