~ubuntu-branches/ubuntu/lucid/xpdf/lucid-updates

« back to all changes in this revision

Viewing changes to debian/patches/30_3.01pl2.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Andy Price
  • Date: 2007-05-17 22:04:33 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517220433-gzcx2lrvllkbl7mr
Tags: 3.02-1ubuntu1
* Merge from Debian unstable (LP: #113365), remaining changes:
  - Added back 09_xpdfrc_manpage.dpatch (LP #71753)
  - Set Ubuntu maintainer

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh /usr/share/dpatch/dpatch-run
2
 
## 30_3.01pl2.dpatch by  <hamish@debian.org>
3
 
##
4
 
## All lines beginning with `## DP:' are a description of the patch.
5
 
## DP: xpdf 3.01pl2 patch provided by upstream
6
 
 
7
 
@DPATCH@
8
 
diff -urNad xpdf-3.01~/goo/gmem.c xpdf-3.01/goo/gmem.c
9
 
--- xpdf-3.01~/goo/gmem.c       2006-02-16 00:14:11.000000000 +1100
10
 
+++ xpdf-3.01/goo/gmem.c        2006-02-16 00:14:28.000000000 +1100
11
 
@@ -11,6 +11,7 @@
12
 
 #include <stdlib.h>
13
 
 #include <stddef.h>
14
 
 #include <string.h>
15
 
+#include <limits.h>
16
 
 #include "gmem.h"
17
 
 
18
 
 #ifdef DEBUG_MEM
19
 
@@ -63,7 +64,7 @@
20
 
   int lst;
21
 
   unsigned long *trl, *p;
22
 
 
23
 
-  if (size == 0)
24
 
+  if (size <= 0)
25
 
     return NULL;
26
 
   size1 = gMemDataSize(size);
27
 
   if (!(mem = (char *)malloc(size1 + gMemHdrSize + gMemTrlSize))) {
28
 
@@ -86,7 +87,7 @@
29
 
 #else
30
 
   void *p;
31
 
 
32
 
-  if (size == 0)
33
 
+  if (size <= 0)
34
 
     return NULL;
35
 
   if (!(p = malloc(size))) {
36
 
     fprintf(stderr, "Out of memory\n");
37
 
@@ -102,7 +103,7 @@
38
 
   void *q;
39
 
   size_t oldSize;
40
 
 
41
 
-  if (size == 0) {
42
 
+  if (size <= 0) {
43
 
     if (p)
44
 
       gfree(p);
45
 
     return NULL;
46
 
@@ -120,7 +121,7 @@
47
 
 #else
48
 
   void *q;
49
 
 
50
 
-  if (size == 0) {
51
 
+  if (size <= 0) {
52
 
     if (p)
53
 
       free(p);
54
 
     return NULL;
55
 
@@ -140,8 +141,11 @@
56
 
 void *gmallocn(int nObjs, size_t objSize) {
57
 
   size_t n;
58
 
 
59
 
+  if (nObjs == 0) {
60
 
+    return NULL;
61
 
+  }
62
 
   n = nObjs * objSize;
63
 
-  if (objSize == 0 || n / objSize != nObjs) {
64
 
+  if (objSize <= 0 || nObjs < 0 || nObjs >= INT_MAX / objSize) {
65
 
     fprintf(stderr, "Bogus memory allocation size\n");
66
 
     exit(1);
67
 
   }
68
 
@@ -151,8 +155,14 @@
69
 
 void *greallocn(void *p, int nObjs, size_t objSize) {
70
 
   size_t n;
71
 
 
72
 
+  if (nObjs == 0) {
73
 
+    if (p) {
74
 
+      gfree(p);
75
 
+    }
76
 
+    return NULL;
77
 
+  }
78
 
   n = nObjs * objSize;
79
 
-  if (objSize == 0 || n / objSize != nObjs) {
80
 
+  if (objSize <= 0 || nObjs < 0 || nObjs >= INT_MAX / objSize) {
81
 
     fprintf(stderr, "Bogus memory allocation size\n");
82
 
     exit(1);
83
 
   }
84
 
diff -urNad xpdf-3.01~/splash/SplashXPathScanner.cc xpdf-3.01/splash/SplashXPathScanner.cc
85
 
--- xpdf-3.01~/splash/SplashXPathScanner.cc     2005-08-17 15:34:31.000000000 +1000
86
 
+++ xpdf-3.01/splash/SplashXPathScanner.cc      2006-02-16 00:14:28.000000000 +1100
87
 
@@ -186,7 +186,7 @@
88
 
 }
89
 
 
90
 
 void SplashXPathScanner::computeIntersections(int y) {
91
 
-  SplashCoord ySegMin, ySegMax, xx0, xx1;
92
 
+  SplashCoord xSegMin, xSegMax, ySegMin, ySegMax, xx0, xx1;
93
 
   SplashXPathSeg *seg;
94
 
   int i, j;
95
 
 
96
 
@@ -236,19 +236,27 @@
97
 
     } else if (seg->flags & splashXPathVert) {
98
 
       xx0 = xx1 = seg->x0;
99
 
     } else {
100
 
-      if (ySegMin <= y) {
101
 
-       // intersection with top edge
102
 
-       xx0 = seg->x0 + ((SplashCoord)y - seg->y0) * seg->dxdy;
103
 
+      if (seg->x0 < seg->x1) {
104
 
+       xSegMin = seg->x0;
105
 
+       xSegMax = seg->x1;
106
 
       } else {
107
 
-       // x coord of segment endpoint with min y coord
108
 
-       xx0 = (seg->flags & splashXPathFlip) ? seg->x1 : seg->x0;
109
 
+       xSegMin = seg->x1;
110
 
+       xSegMax = seg->x0;
111
 
       }
112
 
-      if (ySegMax >= y + 1) {
113
 
-       // intersection with bottom edge
114
 
-       xx1 = seg->x0 + ((SplashCoord)y + 1 - seg->y0) * seg->dxdy;
115
 
-      } else {
116
 
-       // x coord of segment endpoint with max y coord
117
 
-       xx1 = (seg->flags & splashXPathFlip) ? seg->x0 : seg->x1;
118
 
+      // intersection with top edge
119
 
+      xx0 = seg->x0 + ((SplashCoord)y - seg->y0) * seg->dxdy;
120
 
+      // intersection with bottom edge
121
 
+      xx1 = seg->x0 + ((SplashCoord)y + 1 - seg->y0) * seg->dxdy;
122
 
+      // the segment may not actually extend to the top and/or bottom edges
123
 
+      if (xx0 < xSegMin) {
124
 
+       xx0 = xSegMin;
125
 
+      } else if (xx0 > xSegMax) {
126
 
+       xx0 = xSegMax;
127
 
+      }
128
 
+      if (xx1 < xSegMin) {
129
 
+       xx1 = xSegMin;
130
 
+      } else if (xx1 > xSegMax) {
131
 
+       xx1 = xSegMax;
132
 
       }
133
 
     }
134
 
     if (xx0 < xx1) {
135
 
diff -urNad xpdf-3.01~/xpdf/JBIG2Stream.cc xpdf-3.01/xpdf/JBIG2Stream.cc
136
 
--- xpdf-3.01~/xpdf/JBIG2Stream.cc      2006-02-15 23:57:30.000000000 +1100
137
 
+++ xpdf-3.01/xpdf/JBIG2Stream.cc       2006-02-16 00:14:28.000000000 +1100
138
 
@@ -13,6 +13,7 @@
139
 
 #endif
140
 
 
141
 
 #include <stdlib.h>
142
 
+#include <limits.h>
143
 
 #include "GList.h"
144
 
 #include "Error.h"
145
 
 #include "JArithmeticDecoder.h"
146
 
@@ -681,6 +682,10 @@
147
 
   w = wA;
148
 
   h = hA;
149
 
   line = (wA + 7) >> 3;
150
 
+  if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
151
 
+    data = NULL;
152
 
+    return;
153
 
+  }
154
 
   // need to allocate one extra guard byte for use in combine()
155
 
   data = (Guchar *)gmalloc(h * line + 1);
156
 
   data[h * line] = 0;
157
 
@@ -692,6 +697,10 @@
158
 
   w = bitmap->w;
159
 
   h = bitmap->h;
160
 
   line = bitmap->line;
161
 
+  if (w <= 0 || h <= 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
162
 
+    data = NULL;
163
 
+    return;
164
 
+  }
165
 
   // need to allocate one extra guard byte for use in combine()
166
 
   data = (Guchar *)gmalloc(h * line + 1);
167
 
   memcpy(data, bitmap->data, h * line);
168
 
@@ -720,7 +729,7 @@
169
 
 }
170
 
 
171
 
 void JBIG2Bitmap::expand(int newH, Guint pixel) {
172
 
-  if (newH <= h) {
173
 
+  if (newH <= h || line <= 0 || newH >= (INT_MAX - 1) / line) {
174
 
     return;
175
 
   }
176
 
   // need to allocate one extra guard byte for use in combine()
177
 
@@ -2294,6 +2303,14 @@
178
 
       !readUWord(&stepX) || !readUWord(&stepY)) {
179
 
     goto eofError;
180
 
   }
181
 
+  if (w == 0 || h == 0 || w >= INT_MAX / h) {
182
 
+    error(getPos(), "Bad bitmap size in JBIG2 halftone segment");
183
 
+    return;
184
 
+  }
185
 
+  if (gridH == 0 || gridW >= INT_MAX / gridH) {
186
 
+    error(getPos(), "Bad grid size in JBIG2 halftone segment");
187
 
+    return;
188
 
+  }
189
 
 
190
 
   // get pattern dictionary
191
 
   if (nRefSegs != 1) {
192
 
diff -urNad xpdf-3.01~/xpdf/JPXStream.cc xpdf-3.01/xpdf/JPXStream.cc
193
 
--- xpdf-3.01~/xpdf/JPXStream.cc        2006-02-15 23:57:30.000000000 +1100
194
 
+++ xpdf-3.01/xpdf/JPXStream.cc 2006-02-16 00:14:28.000000000 +1100
195
 
@@ -12,6 +12,7 @@
196
 
 #pragma implementation
197
 
 #endif
198
 
 
199
 
+#include <limits.h>
200
 
 #include "gmem.h"
201
 
 #include "Error.h"
202
 
 #include "JArithmeticDecoder.h"
203
 
@@ -818,6 +819,12 @@
204
 
                    / img.xTileSize;
205
 
       img.nYTiles = (img.ySize - img.yTileOffset + img.yTileSize - 1)
206
 
                    / img.yTileSize;
207
 
+      // check for overflow before allocating memory
208
 
+      if (img.nXTiles <= 0 || img.nYTiles <= 0 ||
209
 
+         img.nXTiles >= INT_MAX / img.nYTiles) {
210
 
+       error(getPos(), "Bad tile count in JPX SIZ marker segment");
211
 
+       return gFalse;
212
 
+      }
213
 
       img.tiles = (JPXTile *)gmallocn(img.nXTiles * img.nYTiles,
214
 
                                      sizeof(JPXTile));
215
 
       for (i = 0; i < img.nXTiles * img.nYTiles; ++i) {
216
 
diff -urNad xpdf-3.01~/xpdf/Stream.cc xpdf-3.01/xpdf/Stream.cc
217
 
--- xpdf-3.01~/xpdf/Stream.cc   2006-02-15 23:57:30.000000000 +1100
218
 
+++ xpdf-3.01/xpdf/Stream.cc    2006-02-16 00:14:28.000000000 +1100
219
 
@@ -15,6 +15,7 @@
220
 
 #include <stdio.h>
221
 
 #include <stdlib.h>
222
 
 #include <stddef.h>
223
 
+#include <limits.h>
224
 
 #ifndef WIN32
225
 
 #include <unistd.h>
226
 
 #endif
227
 
@@ -406,13 +407,26 @@
228
 
   width = widthA;
229
 
   nComps = nCompsA;
230
 
   nBits = nBitsA;
231
 
+  predLine = NULL;
232
 
+  ok = gFalse;
233
 
 
234
 
   nVals = width * nComps;
235
 
+  if (width <= 0 || nComps <= 0 || nBits <= 0 ||
236
 
+      nComps >= INT_MAX / nBits ||
237
 
+      width >= INT_MAX / nComps / nBits ||
238
 
+      nVals * nBits + 7 < 0) {
239
 
+    return;
240
 
+  }
241
 
   pixBytes = (nComps * nBits + 7) >> 3;
242
 
   rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes;
243
 
+  if (rowBytes <= 0) {
244
 
+    return;
245
 
+  }
246
 
   predLine = (Guchar *)gmalloc(rowBytes);
247
 
   memset(predLine, 0, rowBytes);
248
 
   predIdx = rowBytes;
249
 
+
250
 
+  ok = gTrue;
251
 
 }
252
 
 
253
 
 StreamPredictor::~StreamPredictor() {
254
 
@@ -1004,6 +1018,10 @@
255
 
     FilterStream(strA) {
256
 
   if (predictor != 1) {
257
 
     pred = new StreamPredictor(this, predictor, columns, colors, bits);
258
 
+    if (!pred->isOk()) {
259
 
+      delete pred;
260
 
+      pred = NULL;
261
 
+    }
262
 
   } else {
263
 
     pred = NULL;
264
 
   }
265
 
@@ -1259,6 +1277,9 @@
266
 
   if (columns < 1) {
267
 
     columns = 1;
268
 
   }
269
 
+  if (columns + 4 <= 0) {
270
 
+    columns = INT_MAX - 4;
271
 
+  }
272
 
   rows = rowsA;
273
 
   endOfBlock = endOfBlockA;
274
 
   black = blackA;
275
 
@@ -2899,6 +2920,11 @@
276
 
   height = read16();
277
 
   width = read16();
278
 
   numComps = str->getChar();
279
 
+  if (numComps <= 0 || numComps > 4) {
280
 
+    error(getPos(), "Bad number of components in DCT stream");
281
 
+    numComps = 0;
282
 
+    return gFalse;
283
 
+  }
284
 
   if (prec != 8) {
285
 
     error(getPos(), "Bad DCT precision %d", prec);
286
 
     return gFalse;
287
 
@@ -2925,6 +2951,11 @@
288
 
   height = read16();
289
 
   width = read16();
290
 
   numComps = str->getChar();
291
 
+  if (numComps <= 0 || numComps > 4) {
292
 
+    error(getPos(), "Bad number of components in DCT stream");
293
 
+    numComps = 0;
294
 
+    return gFalse;
295
 
+  }
296
 
   if (prec != 8) {
297
 
     error(getPos(), "Bad DCT precision %d", prec);
298
 
     return gFalse;
299
 
@@ -2947,6 +2978,11 @@
300
 
 
301
 
   length = read16() - 2;
302
 
   scanInfo.numComps = str->getChar();
303
 
+  if (scanInfo.numComps <= 0 || scanInfo.numComps > 4) {
304
 
+    error(getPos(), "Bad number of components in DCT stream");
305
 
+    scanInfo.numComps = 0;
306
 
+    return gFalse;
307
 
+  }
308
 
   --length;
309
 
   if (length != 2 * scanInfo.numComps + 3) {
310
 
     error(getPos(), "Bad DCT scan info block");
311
 
@@ -3041,6 +3077,7 @@
312
 
        numACHuffTables = index+1;
313
 
       tbl = &acHuffTables[index];
314
 
     } else {
315
 
+      index &= 0x0f;
316
 
       if (index >= numDCHuffTables)
317
 
        numDCHuffTables = index+1;
318
 
       tbl = &dcHuffTables[index];
319
 
@@ -3827,6 +3864,10 @@
320
 
     FilterStream(strA) {
321
 
   if (predictor != 1) {
322
 
     pred = new StreamPredictor(this, predictor, columns, colors, bits);
323
 
+    if (!pred->isOk()) {
324
 
+      delete pred;
325
 
+      pred = NULL;
326
 
+    }
327
 
   } else {
328
 
     pred = NULL;
329
 
   }
330
 
diff -urNad xpdf-3.01~/xpdf/Stream.h xpdf-3.01/xpdf/Stream.h
331
 
--- xpdf-3.01~/xpdf/Stream.h    2006-02-15 23:57:30.000000000 +1100
332
 
+++ xpdf-3.01/xpdf/Stream.h     2006-02-16 00:14:28.000000000 +1100
333
 
@@ -232,6 +232,8 @@
334
 
 
335
 
   ~StreamPredictor();
336
 
 
337
 
+  GBool isOk() { return ok; }
338
 
+
339
 
   int lookChar();
340
 
   int getChar();
341
 
 
342
 
@@ -249,6 +251,7 @@
343
 
   int rowBytes;                        // bytes per line
344
 
   Guchar *predLine;            // line buffer
345
 
   int predIdx;                 // current index in predLine
346
 
+  GBool ok;
347
 
 };
348
 
 
349
 
 //------------------------------------------------------------------------
350
 
@@ -527,7 +530,7 @@
351
 
   short getWhiteCode();
352
 
   short getBlackCode();
353
 
   short lookBits(int n);
354
 
-  void eatBits(int n) { inputBits -= n; }
355
 
+  void eatBits(int n) { if ((inputBits -= n) < 0) inputBits = 0; }
356
 
 };
357
 
 
358
 
 //------------------------------------------------------------------------