Blame SOURCES/libtiff-CVE-2018-8905.patch

b03815
From 1c127eb3cb7653bd61b61f9c3cfeb36fd10edab1 Mon Sep 17 00:00:00 2001
b03815
From: Even Rouault <even.rouault@spatialys.com>
b03815
Date: Sat, 12 May 2018 15:32:31 +0200
b03815
Subject: [PATCH 3/4] LZWDecodeCompat(): fix potential index-out-of-bounds
b03815
 write. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2780 /
b03815
 CVE-2018-8905
b03815
b03815
The fix consists in using the similar code LZWDecode() to validate we
b03815
don't write outside of the output buffer.
b03815
---
b03815
 libtiff/tif_lzw.c | 18 ++++++++++++------
b03815
 1 file changed, 12 insertions(+), 6 deletions(-)
b03815
b03815
diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c
b03815
index bc8f9c8..186ea3c 100644
b03815
--- a/libtiff/tif_lzw.c
b03815
+++ b/libtiff/tif_lzw.c
b03815
@@ -604,6 +604,7 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
b03815
 	char *tp;
b03815
 	unsigned char *bp;
b03815
 	int code, nbits;
b03815
+	int len;
b03815
 	long nextbits, nextdata, nbitsmask;
b03815
 	code_t *codep, *free_entp, *maxcodep, *oldcodep;
b03815
 
b03815
@@ -755,13 +756,18 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
b03815
 				}  while (--occ);
b03815
 				break;
b03815
 			}
b03815
-			assert(occ >= codep->length);
b03815
-			op += codep->length;
b03815
-			occ -= codep->length;
b03815
-			tp = op;
b03815
+			len = codep->length;
b03815
+			tp = op + len;
b03815
 			do {
b03815
-				*--tp = codep->value;
b03815
-			} while( (codep = codep->next) != NULL );
b03815
+				int t;
b03815
+				--tp;
b03815
+				t = codep->value;
b03815
+				codep = codep->next;
b03815
+				*tp = (char)t;
b03815
+			} while (codep && tp > op);
b03815
+			assert(occ >= len);
b03815
+			op += len;
b03815
+			occ -= len;
b03815
 		} else {
b03815
 			*op++ = (char)code;
b03815
 			occ--;
b03815
-- 
b03815
2.17.0
b03815