diff options
author | erouault <erouault> | 2016-10-09 11:03:36 +0000 |
---|---|---|
committer | erouault <erouault> | 2016-10-09 11:03:36 +0000 |
commit | 782d1be02d4cdf5986e0be992715be7d59b150d9 (patch) | |
tree | 21c809e1c48d3999751e9e73c4e54388af6e5a24 /tools | |
parent | cb99cc654213dc3157c776fa68b5ae793bbdd558 (diff) | |
download | libtiff-782d1be02d4cdf5986e0be992715be7d59b150d9.tar.gz |
* tools/tiff2pdf.c: fix write buffer overflow of 2 bytes on JPEG
compressed images. Reported by Tyler Bohan of Cisco Talos as
TALOS-CAN-0187 / CVE-2016-5652.
Also prevents writing 2 extra uninitialized bytes to the file stream.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/tiff2pdf.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c index eb3485e5..63ffa961 100644 --- a/tools/tiff2pdf.c +++ b/tools/tiff2pdf.c @@ -1,4 +1,4 @@ -/* $Id: tiff2pdf.c,v 1.93 2016-10-08 15:14:42 erouault Exp $ +/* $Id: tiff2pdf.c,v 1.94 2016-10-09 11:03:36 erouault Exp $ * * tiff2pdf - converts a TIFF image to a PDF document * @@ -2887,21 +2887,24 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_ return(0); } if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) { - if (count >= 2) { - _TIFFmemcpy(buffer, jpt, count); + if (count >= 4) { + /* Ignore EOI marker of JpegTables */ + _TIFFmemcpy(buffer, jpt, count - 2); bufferoffset += count - 2; + /* Store last 2 bytes of the JpegTables */ table_end[0] = buffer[bufferoffset-2]; table_end[1] = buffer[bufferoffset-1]; - } - if (count >= 2) { xuint32 = bufferoffset; + bufferoffset -= 2; bufferoffset += TIFFReadRawTile( input, tile, - (tdata_t) &(((unsigned char*)buffer)[bufferoffset-2]), + (tdata_t) &(((unsigned char*)buffer)[bufferoffset]), -1); - buffer[xuint32-2]=table_end[0]; - buffer[xuint32-1]=table_end[1]; + /* Overwrite SOI marker of image scan with previously */ + /* saved end of JpegTables */ + buffer[xuint32-2]=table_end[0]; + buffer[xuint32-1]=table_end[1]; } else { bufferoffset += TIFFReadRawTile( input, |