|
|
7c98bb |
Upstream patch for CVE-2012-4564.
|
|
|
7c98bb |
|
|
|
7c98bb |
|
|
|
7c98bb |
diff -Naur tiff-3.9.4.orig/tools/ppm2tiff.c tiff-3.9.4/tools/ppm2tiff.c
|
|
|
7c98bb |
--- tiff-3.9.4.orig/tools/ppm2tiff.c 2010-06-08 14:50:44.000000000 -0400
|
|
|
7c98bb |
+++ tiff-3.9.4/tools/ppm2tiff.c 2012-12-10 16:16:05.154045877 -0500
|
|
|
7c98bb |
@@ -68,6 +68,17 @@
|
|
|
7c98bb |
exit(-2);
|
|
|
7c98bb |
}
|
|
|
7c98bb |
|
|
|
7c98bb |
+static tsize_t
|
|
|
7c98bb |
+multiply_ms(tsize_t m1, tsize_t m2)
|
|
|
7c98bb |
+{
|
|
|
7c98bb |
+ tsize_t bytes = m1 * m2;
|
|
|
7c98bb |
+
|
|
|
7c98bb |
+ if (m1 && bytes / m1 != m2)
|
|
|
7c98bb |
+ bytes = 0;
|
|
|
7c98bb |
+
|
|
|
7c98bb |
+ return bytes;
|
|
|
7c98bb |
+}
|
|
|
7c98bb |
+
|
|
|
7c98bb |
int
|
|
|
7c98bb |
main(int argc, char* argv[])
|
|
|
7c98bb |
{
|
|
|
7c98bb |
@@ -85,6 +96,7 @@
|
|
|
7c98bb |
int c;
|
|
|
7c98bb |
extern int optind;
|
|
|
7c98bb |
extern char* optarg;
|
|
|
7c98bb |
+ tsize_t scanline_size;
|
|
|
7c98bb |
|
|
|
7c98bb |
if (argc < 2) {
|
|
|
7c98bb |
fprintf(stderr, "%s: Too few arguments\n", argv[0]);
|
|
|
7c98bb |
@@ -217,7 +229,8 @@
|
|
|
7c98bb |
}
|
|
|
7c98bb |
switch (bpp) {
|
|
|
7c98bb |
case 1:
|
|
|
7c98bb |
- linebytes = (spp * w + (8 - 1)) / 8;
|
|
|
7c98bb |
+ /* if round-up overflows, result will be zero, OK */
|
|
|
7c98bb |
+ linebytes = (multiply_ms(spp, w) + (8 - 1)) / 8;
|
|
|
7c98bb |
if (rowsperstrip == (uint32) -1) {
|
|
|
7c98bb |
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, h);
|
|
|
7c98bb |
} else {
|
|
|
7c98bb |
@@ -226,15 +239,31 @@
|
|
|
7c98bb |
}
|
|
|
7c98bb |
break;
|
|
|
7c98bb |
case 8:
|
|
|
7c98bb |
- linebytes = spp * w;
|
|
|
7c98bb |
+ linebytes = multiply_ms(spp, w);
|
|
|
7c98bb |
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
|
|
|
7c98bb |
TIFFDefaultStripSize(out, rowsperstrip));
|
|
|
7c98bb |
break;
|
|
|
7c98bb |
}
|
|
|
7c98bb |
- if (TIFFScanlineSize(out) > linebytes)
|
|
|
7c98bb |
+ if (linebytes == 0) {
|
|
|
7c98bb |
+ fprintf(stderr, "%s: scanline size overflow\n", infile);
|
|
|
7c98bb |
+ (void) TIFFClose(out);
|
|
|
7c98bb |
+ exit(-2);
|
|
|
7c98bb |
+ }
|
|
|
7c98bb |
+ scanline_size = TIFFScanlineSize(out);
|
|
|
7c98bb |
+ if (scanline_size == 0) {
|
|
|
7c98bb |
+ /* overflow - TIFFScanlineSize already printed a message */
|
|
|
7c98bb |
+ (void) TIFFClose(out);
|
|
|
7c98bb |
+ exit(-2);
|
|
|
7c98bb |
+ }
|
|
|
7c98bb |
+ if (scanline_size < linebytes)
|
|
|
7c98bb |
buf = (unsigned char *)_TIFFmalloc(linebytes);
|
|
|
7c98bb |
else
|
|
|
7c98bb |
- buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
|
|
|
7c98bb |
+ buf = (unsigned char *)_TIFFmalloc(scanline_size);
|
|
|
7c98bb |
+ if (buf == NULL) {
|
|
|
7c98bb |
+ fprintf(stderr, "%s: Not enough memory\n", infile);
|
|
|
7c98bb |
+ (void) TIFFClose(out);
|
|
|
7c98bb |
+ exit(-2);
|
|
|
7c98bb |
+ }
|
|
|
7c98bb |
if (resolution > 0) {
|
|
|
7c98bb |
TIFFSetField(out, TIFFTAG_XRESOLUTION, resolution);
|
|
|
7c98bb |
TIFFSetField(out, TIFFTAG_YRESOLUTION, resolution);
|