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