Blame SOURCES/0008-CVE-2018-8905-LZWDecodeCompat-fix-potential-index-ou.patch

edc570
From 54972f69399628fd2105753cbcddb36ede510507 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
edc570
Subject: [PATCH] (CVE-2018-8905) LZWDecodeCompat(): fix potential
edc570
 index-out-of-bounds write. Fixes
edc570
 http://bugzilla.maptools.org/show_bug.cgi?id=2780 / 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.
edc570
edc570
(cherry picked from commit 58a898cb4459055bb488ca815c23b880c242a27d)
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
edc570
index bc8f9c84..186ea3ca 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
-- 
edc570
2.34.1
b03815