summaryrefslogtreecommitdiff
path: root/geography/gdal-lib/patches/patch-CVE-2011-1167
blob: 1887d3cad350f09c36265b9a455efdda84f5d0d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
$NetBSD: patch-CVE-2011-1167,v 1.1 2011/03/31 11:08:29 drochner Exp $

--- frmts/gtiff/libtiff/tif_thunder.c.orig	2011-01-14 05:19:04.000000000 +0000
+++ frmts/gtiff/libtiff/tif_thunder.c
@@ -25,6 +25,7 @@
  */
 
 #include "tiffiop.h"
+#include <assert.h>
 #ifdef THUNDER_SUPPORT
 /*
  * TIFF Library.
@@ -55,15 +56,35 @@
 static const int twobitdeltas[4] = { 0, 1, 0, -1 };
 static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 };
 
-#define	SETPIXEL(op, v) { \
-	lastpixel = (v) & 0xf; \
-	if (npixels++ & 1) \
-	    *op++ |= lastpixel; \
-	else \
-	    op[0] = (uint8) (lastpixel << 4); \
+#define        SETPIXEL(op, v) {                     \
+       lastpixel = (v) & 0xf;                \
+        if ( npixels < maxpixels )         \
+        {                                     \
+         if (npixels++ & 1)                  \
+           *op++ |= lastpixel;               \
+         else                                \
+            op[0] = (uint8) (lastpixel << 4); \
+        }                                     \
 }
 
 static int
+ThunderSetupDecode(TIFF* tif)
+{
+       static const char module[] = "ThunderSetupDecode";
+
+        if( tif->tif_dir.td_bitspersample != 4 )
+        {
+                TIFFErrorExt(tif->tif_clientdata, module,
+                             "Wrong bitspersample value (%d), Thunder decoder only supports 4bits per sample.",
+                             (int) tif->tif_dir.td_bitspersample );
+                return 0;
+        }
+
+
+       return (1);
+ }
+
+static int
 ThunderDecode(TIFF* tif, uint8* op, tmsize_t maxpixels)
 {
 	static const char module[] = "ThunderDecode";
@@ -160,7 +181,8 @@ ThunderDecodeRow(TIFF* tif, uint8* buf, 
 		occ -= tif->tif_scanlinesize;
 		row += tif->tif_scanlinesize;
 	}
-	return (1);
+
+        return (1);
 }
 
 int
@@ -169,6 +191,7 @@ TIFFInitThunderScan(TIFF* tif, int schem
 	(void) scheme;
 	tif->tif_decoderow = ThunderDecodeRow;
 	tif->tif_decodestrip = ThunderDecodeRow; 
+	tif->tif_setupdecode = ThunderSetupDecode;
 	return (1);
 }
 #endif /* THUNDER_SUPPORT */