|
|
ccba1e |
From 0bbe164e12be733a1b7e0fe9939ea3461ed7fff2 Mon Sep 17 00:00:00 2001
|
|
|
ccba1e |
From: 4ugustus <wangdw.augustus@qq.com>
|
|
|
ccba1e |
Date: Thu, 10 Mar 2022 08:48:00 +0000
|
|
|
ccba1e |
Subject: [PATCH] (CVE-2022-0924) fix heap buffer overflow in tiffcp (#278)
|
|
|
ccba1e |
|
|
|
ccba1e |
(cherry picked from commit 88d79a45a31c74cba98c697892fed5f7db8b963a)
|
|
|
ccba1e |
---
|
|
|
ccba1e |
tools/tiffcp.c | 17 ++++++++++++++++-
|
|
|
ccba1e |
1 file changed, 16 insertions(+), 1 deletion(-)
|
|
|
ccba1e |
|
|
|
ccba1e |
diff --git a/tools/tiffcp.c b/tools/tiffcp.c
|
|
|
ccba1e |
index 96f14728..d5f1d248 100644
|
|
|
ccba1e |
--- a/tools/tiffcp.c
|
|
|
ccba1e |
+++ b/tools/tiffcp.c
|
|
|
ccba1e |
@@ -1506,12 +1506,27 @@ DECLAREwriteFunc(writeBufferToSeparateStrips)
|
|
|
ccba1e |
tdata_t obuf;
|
|
|
ccba1e |
tstrip_t strip = 0;
|
|
|
ccba1e |
tsample_t s;
|
|
|
ccba1e |
+ uint16 bps = 0, bytes_per_sample;
|
|
|
ccba1e |
|
|
|
ccba1e |
obuf = _TIFFmalloc(stripsize);
|
|
|
ccba1e |
if (obuf == NULL)
|
|
|
ccba1e |
return (0);
|
|
|
ccba1e |
_TIFFmemset(obuf, 0, stripsize);
|
|
|
ccba1e |
(void) TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
|
|
|
ccba1e |
+ (void) TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps;;
|
|
|
ccba1e |
+ if( bps == 0 )
|
|
|
ccba1e |
+ {
|
|
|
ccba1e |
+ TIFFError(TIFFFileName(out), "Error, cannot read BitsPerSample");
|
|
|
ccba1e |
+ _TIFFfree(obuf);
|
|
|
ccba1e |
+ return 0;
|
|
|
ccba1e |
+ }
|
|
|
ccba1e |
+ if( (bps % 8) != 0 )
|
|
|
ccba1e |
+ {
|
|
|
ccba1e |
+ TIFFError(TIFFFileName(out), "Error, cannot handle BitsPerSample that is not a multiple of 8");
|
|
|
ccba1e |
+ _TIFFfree(obuf);
|
|
|
ccba1e |
+ return 0;
|
|
|
ccba1e |
+ }
|
|
|
ccba1e |
+ bytes_per_sample = bps/8;
|
|
|
ccba1e |
for (s = 0; s < spp; s++) {
|
|
|
ccba1e |
uint32 row;
|
|
|
ccba1e |
for (row = 0; row < imagelength; row += rowsperstrip) {
|
|
|
ccba1e |
@@ -1521,7 +1536,7 @@ DECLAREwriteFunc(writeBufferToSeparateStrips)
|
|
|
ccba1e |
|
|
|
ccba1e |
cpContigBufToSeparateBuf(
|
|
|
ccba1e |
obuf, (uint8*) buf + row*rowsize + s,
|
|
|
ccba1e |
- nrows, imagewidth, 0, 0, spp, 1);
|
|
|
ccba1e |
+ nrows, imagewidth, 0, 0, spp, bytes_per_sample);
|
|
|
ccba1e |
if (TIFFWriteEncodedStrip(out, strip++, obuf, stripsize) < 0) {
|
|
|
ccba1e |
TIFFError(TIFFFileName(out),
|
|
|
ccba1e |
"Error, can't write strip %u",
|