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

53 lines
1.5 KiB
Diff
Raw Normal View History

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