summaryrefslogtreecommitdiff
path: root/third_party/libtiff/0017-safe_skews_in_gtTileContig.patch
blob: 9fc0ed0cc9e22af6bbfb49a89a8779e576d10e8a (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
diff --git a/third_party/libtiff/0017-safe_skews_in_gtTileContig.patch b/third_party/libtiff/0017-safe_skews_in_gtTileContig.patch
index ad6d33dae..e69de29bb 100644
--- a/third_party/libtiff/0017-safe_skews_in_gtTileContig.patch
+++ b/third_party/libtiff/0017-safe_skews_in_gtTileContig.patch
@@ -1,88 +0,0 @@
-diff --git a/third_party/libtiff/tif_getimage.c b/third_party/libtiff/tif_getimage.c
-index 84cc1d1a7..82e19164e 100644
---- a/third_party/libtiff/tif_getimage.c
-+++ b/third_party/libtiff/tif_getimage.c
-@@ -31,6 +31,7 @@
-  */
- #include "tiffiop.h"
- #include <stdio.h>
-+#include <limits.h>
- 
- static int gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32);
- static int gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32);
-@@ -629,6 +628,7 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
-     uint32 tw, th;
-     unsigned char* buf;
-     int32 fromskew, toskew;
-+    int64 safeskew;
-     uint32 nrow;
-     int ret = 1, flip;
-     uint32 this_tw, tocol;
-@@ -649,19 +647,37 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
-     flip = setorientation(img);
-     if (flip & FLIP_VERTICALLY) {
- 	    y = h - 1;
--	    toskew = -(int32)(tw + w);
-+	    safeskew = 0;
-+	    safeskew -= tw;
-+	    safeskew -= w;
-     }
-     else {
- 	    y = 0;
--	    toskew = -(int32)(tw - w);
-+	    safeskew = 0;
-+	    safeskew -= tw;
-+	    safeskew +=w;
-     }
-      
-+    if(safeskew > INT_MAX || safeskew < INT_MIN){
-+       _TIFFfree(buf);
-+       TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew");
-+       return (0);
-+    }
-+    toskew = safeskew;
-+
-     /*
-      *	Leftmost tile is clipped on left side if col_offset > 0.
-      */
-     leftmost_fromskew = img->col_offset % tw;
-     leftmost_tw = tw - leftmost_fromskew;
--    leftmost_toskew = toskew + leftmost_fromskew;
-+    safeskew = toskew;
-+    safeskew += leftmost_fromskew;
-+    if(safeskew > INT_MAX || safeskew < INT_MIN){
-+       _TIFFfree(buf);
-+       TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew");
-+       return (0);
-+    }
-+    leftmost_toskew = safeskew;
-     for (row = 0; row < h; row += nrow)
-     {
-         rowstoread = th - (row + img->row_offset) % th;
-@@ -704,9 +684,24 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
- 		/*
- 		 * Rightmost tile is clipped on right side.
- 		 */
--		fromskew = tw - (w - tocol);
-+		safeskew = tw;
-+		safeskew -= w;
-+		safeskew += tocol;
-+		if(safeskew > INT_MAX || safeskew < INT_MIN){
-+		        _TIFFfree(buf);
-+		        TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew");
-+		        return (0);
-+		}
-+		fromskew = safeskew;
- 		this_tw = tw - fromskew;
--		this_toskew = toskew + fromskew;
-+		safeskew = toskew;
-+		safeskew += fromskew;
-+		if(safeskew > INT_MAX || safeskew < INT_MIN){
-+		        _TIFFfree(buf);
-+		        TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew");
-+		        return (0);
-+		}
-+		this_toskew = safeskew;
- 	    }
- 	    (*put)(img, raster+y*w+tocol, tocol, y, this_tw, nrow, fromskew, this_toskew, buf + pos);
- 	    tocol += this_tw;
diff --git a/third_party/libtiff/tif_getimage.c b/third_party/libtiff/tif_getimage.c
index fc554ccab..fff3f7fde 100644
--- a/third_party/libtiff/tif_getimage.c
+++ b/third_party/libtiff/tif_getimage.c
@@ -31,6 +31,7 @@
  */
 #include "tiffiop.h"
 #include <stdio.h>
+#include <limits.h>
 
 static int gtTileContig(TIFFRGBAImage*, uint32*, uint32, uint32);
 static int gtTileSeparate(TIFFRGBAImage*, uint32*, uint32, uint32);
@@ -628,6 +629,7 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
     uint32 tw, th;
     unsigned char* buf = NULL;
     int32 fromskew, toskew;
+    int64 safeskew;
     uint32 nrow;
     int ret = 1, flip;
     uint32 this_tw, tocol;
@@ -648,19 +650,37 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
     flip = setorientation(img);
     if (flip & FLIP_VERTICALLY) {
 	    y = h - 1;
-	    toskew = -(int32)(tw + w);
+	    safeskew = 0;
+	    safeskew -= tw;
+	    safeskew -= w;
     }
     else {
 	    y = 0;
-	    toskew = -(int32)(tw - w);
+	    safeskew = 0;
+	    safeskew -= tw;
+	    safeskew +=w;
     }
      
+    if(safeskew > INT_MAX || safeskew < INT_MIN){
+       _TIFFfree(buf);
+       TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew");
+       return (0);
+    }
+    toskew = safeskew;
+
     /*
      *	Leftmost tile is clipped on left side if col_offset > 0.
      */
     leftmost_fromskew = img->col_offset % tw;
     leftmost_tw = tw - leftmost_fromskew;
-    leftmost_toskew = toskew + leftmost_fromskew;
+    safeskew = toskew;
+    safeskew += leftmost_fromskew;
+    if(safeskew > INT_MAX || safeskew < INT_MIN){
+       _TIFFfree(buf);
+       TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew");
+       return (0);
+    }
+    leftmost_toskew = safeskew;
     for (row = 0; ret != 0 && row < h; row += nrow)
     {
         rowstoread = th - (row + img->row_offset) % th;
@@ -686,9 +706,24 @@ gtTileContig(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
 		/*
 		 * Rightmost tile is clipped on right side.
 		 */
-		fromskew = tw - (w - tocol);
+		safeskew = tw;
+		safeskew -= w;
+		safeskew += tocol;
+		if(safeskew > INT_MAX || safeskew < INT_MIN){
+		        _TIFFfree(buf);
+		        TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew");
+		        return (0);
+		}
+		fromskew = safeskew;
 		this_tw = tw - fromskew;
-		this_toskew = toskew + fromskew;
+		safeskew = toskew;
+		safeskew += fromskew;
+		if(safeskew > INT_MAX || safeskew < INT_MIN){
+		        _TIFFfree(buf);
+		        TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", "Invalid skew");
+		        return (0);
+		}
+		this_toskew = safeskew;
 	    }
 	    (*put)(img, raster+y*w+tocol, tocol, y, this_tw, nrow, fromskew, this_toskew, buf + pos);
 	    tocol += this_tw;