Blame SOURCES/libtiff-CVE-2016-3945.patch

460672
From a9bb0f1406e9da35da4da13eabacb00d9cc2efcb Mon Sep 17 00:00:00 2001
460672
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
460672
Date: Mon, 11 Jul 2016 16:05:49 +0200
460672
Subject: [PATCH 5/8] Fix CVE-2016-3945
460672
460672
---
460672
 tools/tiff2rgba.c | 34 ++++++++++++++++++++++++++++++----
460672
 1 file changed, 30 insertions(+), 4 deletions(-)
460672
460672
diff --git a/tools/tiff2rgba.c b/tools/tiff2rgba.c
460672
index 737167c..5228966 100644
460672
--- a/tools/tiff2rgba.c
460672
+++ b/tools/tiff2rgba.c
460672
@@ -145,6 +145,7 @@ cvt_by_tile( TIFF *in, TIFF *out )
460672
     uint32  row, col;
460672
     uint32  *wrk_line;
460672
     int	    ok = 1;
460672
+    uint32  rastersize, wrk_linesize;
460672
 
460672
     TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width);
460672
     TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height);
460672
@@ -161,7 +162,13 @@ cvt_by_tile( TIFF *in, TIFF *out )
460672
     /*
460672
      * Allocate tile buffer
460672
      */
460672
-    raster = (uint32*)_TIFFmalloc(tile_width * tile_height * sizeof (uint32));
460672
+    rastersize = tile_width * tile_height * sizeof (uint32);
460672
+    if (width != (tile_width / tile_height) / sizeof( uint32))
460672
+    {
460672
+	TIFFError(TIFFFileName(in), "Integer overflow when calculating raster buffer");
460672
+	exit(-1);
460672
+    }
460672
+    raster = (uint32*)_TIFFmalloc(rastersize);
460672
     if (raster == 0) {
460672
         TIFFError(TIFFFileName(in), "No space for raster buffer");
460672
         return (0);
460672
@@ -171,7 +178,13 @@ cvt_by_tile( TIFF *in, TIFF *out )
460672
      * Allocate a scanline buffer for swapping during the vertical
460672
      * mirroring pass.
460672
      */
460672
-    wrk_line = (uint32*)_TIFFmalloc(tile_width * sizeof (uint32));
460672
+    wrk_linesize = tile_width * sizeof (uint32);
460672
+    if (wrk_linesize != tile_width / sizeof (uint32))
460672
+    {
460672
+        TIFFError(TIFFFileName(in), "Integer overflow when calculating wrk_line buffer");
460672
+	exit(-1);
460672
+    }
460672
+    wrk_line = (uint32*)_TIFFmalloc(wrk_linesize);
460672
     if (!wrk_line) {
460672
         TIFFError(TIFFFileName(in), "No space for raster scanline buffer");
460672
         ok = 0;
460672
@@ -247,6 +260,7 @@ cvt_by_strip( TIFF *in, TIFF *out )
460672
     uint32  row;
460672
     uint32  *wrk_line;
460672
     int	    ok = 1;
460672
+    uint32  rastersize, wrk_linesize;
460672
 
460672
     TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width);
460672
     TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height);
460672
@@ -261,7 +275,13 @@ cvt_by_strip( TIFF *in, TIFF *out )
460672
     /*
460672
      * Allocate strip buffer
460672
      */
460672
-    raster = (uint32*)_TIFFmalloc(width * rowsperstrip * sizeof (uint32));
460672
+    rastersize = width * rowsperstrip * sizeof (uint32);
460672
+    if (width != (rastersize / rowsperstrip) / sizeof( uint32))
460672
+    {
460672
+	TIFFError(TIFFFileName(in), "Integer overflow when calculating raster buffer");
460672
+	exit(-1);
460672
+    }
460672
+    raster = (uint32*)_TIFFmalloc(rastersize);
460672
     if (raster == 0) {
460672
         TIFFError(TIFFFileName(in), "No space for raster buffer");
460672
         return (0);
460672
@@ -271,7 +291,13 @@ cvt_by_strip( TIFF *in, TIFF *out )
460672
      * Allocate a scanline buffer for swapping during the vertical
460672
      * mirroring pass.
460672
      */
460672
-    wrk_line = (uint32*)_TIFFmalloc(width * sizeof (uint32));
460672
+    wrk_linesize = width * sizeof (uint32);
460672
+    if (wrk_linesize != width / sizeof (uint32))
460672
+    {
460672
+        TIFFError(TIFFFileName(in), "Integer overflow when calculating wrk_line buffer");
460672
+	exit(-1);
460672
+    }
460672
+    wrk_line = (uint32*)_TIFFmalloc(wrk_linesize);
460672
     if (!wrk_line) {
460672
         TIFFError(TIFFFileName(in), "No space for raster scanline buffer");
460672
         ok = 0;
460672
-- 
460672
2.7.4
460672