]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/gpdf/files/006_CAN-2005-3191.patch
gpdf: add 2.10.0-4 from Debian.
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / gpdf / files / 006_CAN-2005-3191.patch
1 diff -u -p -Nr --exclude CVS xpdf/JBIG2Stream.cc xpdf/JBIG2Stream.cc
2 --- xpdf/JBIG2Stream.cc 2004-05-17 20:11:43.000000000 +0200
3 +++ xpdf/JBIG2Stream.cc 2005-12-15 13:38:04.000000000 +0100
4 @@ -7,6 +7,7 @@
5  //========================================================================
6  
7  #include <aconf.h>
8 +#include <limits.h>
9  
10  #ifdef USE_GCC_PRAGMAS
11  #pragma implementation
12 @@ -681,7 +682,14 @@ JBIG2Bitmap::JBIG2Bitmap(Guint segNumA, 
13    w = wA;
14    h = hA;
15    line = (wA + 7) >> 3;
16 -  data = (Guchar *)gmalloc(h * line);
17 +
18 +  if (h < 0 || line <= 0 || h >= (INT_MAX-1) / line)
19 +    data = NULL;
20 +  else {
21 +    // need to allocate one extra guard byte for use in combine()
22 +    data = (Guchar *)gmalloc(h * line + 1);
23 +    data[h * line] = 0;
24 +  }
25  }
26  
27  JBIG2Bitmap::JBIG2Bitmap(Guint segNumA, JBIG2Bitmap *bitmap):
28 @@ -690,8 +698,16 @@ JBIG2Bitmap::JBIG2Bitmap(Guint segNumA, 
29    w = bitmap->w;
30    h = bitmap->h;
31    line = bitmap->line;
32 -  data = (Guchar *)gmalloc(h * line);
33 +
34 +  if (h < 0 || line <= 0 || h >= (INT_MAX-1) / line) {
35 +    data = NULL;
36 +    return;
37 +  }
38 +
39 +  data = (Guchar *)gmalloc(h * line + 1);
40 +
41    memcpy(data, bitmap->data, h * line);
42 +  data[h * line] = 0;
43  }
44  
45  JBIG2Bitmap::~JBIG2Bitmap() {
46 @@ -716,10 +732,10 @@ JBIG2Bitmap *JBIG2Bitmap::getSlice(Guint
47  }
48  
49  void JBIG2Bitmap::expand(int newH, Guint pixel) {
50 -  if (newH <= h) {
51 +  if (newH <= h || line <= 0 || newH >= (INT_MAX-1) / line) {
52      return;
53    }
54 -  data = (Guchar *)grealloc(data, newH * line);
55 +  data = (Guchar *)grealloc(data, newH * line + 1);
56    if (pixel) {
57      memset(data + h * line, 0xff, (newH - h) * line);
58    } else {
59 @@ -2256,6 +2272,16 @@ void JBIG2Stream::readHalftoneRegionSeg(
60      error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
61      return;
62    }
63 +
64 +  if (gridH == 0 || gridW >= INT_MAX / gridH) {
65 +    error(getPos(), "Bad size in JBIG2 halftone segment");
66 +    return;
67 +  }
68 +  if (w == 0 || h >= INT_MAX / w) {
69 +    error(getPos(), "Bad size in JBIG2 bitmap segment");
70 +    return;
71 +  }
72 +
73    patternDict = (JBIG2PatternDict *)seg;
74    bpp = 0;
75    i = 1;
76 @@ -2887,6 +2913,9 @@ JBIG2Bitmap *JBIG2Stream::readGenericRef
77    JBIG2BitmapPtr tpgrCXPtr0, tpgrCXPtr1, tpgrCXPtr2;
78    int x, y, pix;
79  
80 +  if (w < 0 || h <= 0 || w >= INT_MAX / h)
81 +    return NULL;
82 +
83    bitmap = new JBIG2Bitmap(0, w, h);
84    bitmap->clearToZero();
85  
86 diff -u -p -Nr --exclude CVS xpdf/JPXStream.cc xpdf/JPXStream.cc
87 --- xpdf/JPXStream.cc   2004-05-17 20:11:49.000000000 +0200
88 +++ xpdf/JPXStream.cc   2005-12-15 13:23:59.000000000 +0100
89 @@ -7,6 +7,7 @@
90  //========================================================================
91  
92  #include <aconf.h>
93 +#include <limits.h>
94  
95  #ifdef USE_GCC_PRAGMAS
96  #pragma implementation
97 @@ -666,7 +667,7 @@ GBool JPXStream::readCodestream(Guint le
98    int segType;
99    GBool haveSIZ, haveCOD, haveQCD, haveSOT;
100    Guint precinctSize, style;
101 -  Guint segLen, capabilities, comp, i, j, r;
102 +  Guint segLen, capabilities, nTiles, comp, i, j, r;
103  
104    //----- main header
105    haveSIZ = haveCOD = haveQCD = haveSOT = gFalse;
106 @@ -701,7 +702,19 @@ GBool JPXStream::readCodestream(Guint le
107                     / img.xTileSize;
108        img.nYTiles = (img.ySize - img.yTileOffset + img.yTileSize - 1)
109                     / img.yTileSize;
110 -      img.tiles = (JPXTile *)gmalloc(img.nXTiles * img.nYTiles *
111 +      // check for overflow before allocating memory
112 +      if (img.nXTiles <= 0 || img.nYTiles <= 0 ||
113 +         img.nXTiles >= INT_MAX/img.nYTiles) {
114 +       error(getPos(), "Bad tile count in JPX SIZ marker segment");
115 +       return gFalse;
116 +      }
117 +      nTiles = img.nXTiles * img.nYTiles;
118 +      // check for overflow before allocating memory
119 +      if (nTiles == 0 || nTiles >= INT_MAX/sizeof(JPXTile)) {
120 +       error(getPos(), "Bad tile count in JPX SIZ marker segment");
121 +       return gFalse;
122 +      }
123 +      img.tiles = (JPXTile *)gmalloc(nTiles *
124                                      sizeof(JPXTile));
125        for (i = 0; i < img.nXTiles * img.nYTiles; ++i) {
126         img.tiles[i].tileComps = (JPXTileComp *)gmalloc(img.nComps *
127 diff -u -p -Nr --exclude CVS xpdf/Stream.cc xpdf/Stream.cc
128 --- xpdf/Stream.cc      2004-05-17 21:37:57.000000000 +0200
129 +++ xpdf/Stream.cc      2005-12-15 13:40:45.000000000 +0100
130 @@ -15,6 +15,7 @@
131  #include <stdio.h>
132  #include <stdlib.h>
133  #include <stddef.h>
134 +#include <limits.h>
135  #ifndef WIN32
136  #include <unistd.h>
137  #endif
138 @@ -407,18 +408,41 @@ void ImageStream::skipLine() {
139  
140  StreamPredictor::StreamPredictor(Stream *strA, int predictorA,
141                                  int widthA, int nCompsA, int nBitsA) {
142 +  int totalBits;
143 +
144    str = strA;
145    predictor = predictorA;
146    width = widthA;
147    nComps = nCompsA;
148    nBits = nBitsA;
149 +  predLine = NULL;
150 +  ok = gFalse;
151  
152 +  if (width <= 0 || nComps <= 0 || nBits <= 0 ||
153 +      nComps >= INT_MAX/nBits ||
154 +      width >= INT_MAX/nComps/nBits) {
155 +    return;
156 +  }
157    nVals = width * nComps;
158 +  if (nVals + 7 <= 0) {
159 +    return;
160 +  }
161 +  totalBits = nVals * nBits;
162 +  if (totalBits == 0 ||
163 +      (totalBits / nBits) / nComps != width ||
164 +      totalBits + 7 < 0) {
165 +    return;
166 +  }
167    pixBytes = (nComps * nBits + 7) >> 3;
168 -  rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes;
169 +  rowBytes = ((totalBits + 7) >> 3) + pixBytes;
170 +  if (rowBytes < 0) {
171 +    return;
172 +  }
173    predLine = (Guchar *)gmalloc(rowBytes);
174    memset(predLine, 0, rowBytes);
175    predIdx = rowBytes;
176 +
177 +  ok = gTrue;
178  }
179  
180  StreamPredictor::~StreamPredictor() {
181 @@ -1012,6 +1036,10 @@ LZWStream::LZWStream(Stream *strA, int p
182      FilterStream(strA) {
183    if (predictor != 1) {
184      pred = new StreamPredictor(this, predictor, columns, colors, bits);
185 +    if (!pred->isOk()) {
186 +      delete pred;
187 +      pred = NULL;
188 +    }
189    } else {
190      pred = NULL;
191    }
192 @@ -1260,6 +1288,10 @@ CCITTFaxStream::CCITTFaxStream(Stream *s
193    endOfLine = endOfLineA;
194    byteAlign = byteAlignA;
195    columns = columnsA;
196 +  if (columns + 4 < 1 || (columns + 4) >= INT_MAX / sizeof(short)) {
197 +    error(getPos(), "Bad number of columns in CCITTFaxStream");
198 +    exit(1);
199 +  }
200    rows = rowsA;
201    endOfBlock = endOfBlockA;
202    black = blackA;
203 @@ -2897,6 +2929,11 @@ GBool DCTStream::readBaselineSOF() {
204    height = read16();
205    width = read16();
206    numComps = str->getChar();
207 +  if (numComps <= 0 || numComps > 4) {
208 +    numComps = 0;
209 +    error(getPos(), "Bad number of components in DCT stream", prec);
210 +    return gFalse;
211 +  }
212    if (prec != 8) {
213      error(getPos(), "Bad DCT precision %d", prec);
214      return gFalse;
215 @@ -2923,6 +2960,11 @@ GBool DCTStream::readProgressiveSOF() {
216    height = read16();
217    width = read16();
218    numComps = str->getChar();
219 +  if (numComps <= 0 || numComps > 4) {
220 +    numComps = 0;
221 +    error(getPos(), "Bad number of components in DCT stream");
222 +    return gFalse;
223 +  }
224    if (prec != 8) {
225      error(getPos(), "Bad DCT precision %d", prec);
226      return gFalse;
227 @@ -2945,6 +2987,11 @@ GBool DCTStream::readScanInfo() {
228  
229    length = read16() - 2;
230    scanInfo.numComps = str->getChar();
231 +  if (scanInfo.numComps <= 0 || scanInfo.numComps > 4) {
232 +    scanInfo.numComps = 0;
233 +    error(getPos(), "Bad number of components in DCT stream");
234 +    return gFalse;
235 +  }
236    --length;
237    if (length != 2 * scanInfo.numComps + 3) {
238      error(getPos(), "Bad DCT scan info block");
239 @@ -3019,12 +3066,12 @@ GBool DCTStream::readHuffmanTables() {
240    while (length > 0) {
241      index = str->getChar();
242      --length;
243 -    if ((index & 0x0f) >= 4) {
244 +    if ((index & ~0x10) >= 4 || (index & ~0x10) < 0) {
245        error(getPos(), "Bad DCT Huffman table");
246        return gFalse;
247      }
248      if (index & 0x10) {
249 -      index &= 0x0f;
250 +      index &= 0x03;
251        if (index >= numACHuffTables)
252         numACHuffTables = index+1;
253        tbl = &acHuffTables[index];
254 @@ -3255,6 +3302,10 @@ FlateStream::FlateStream(Stream *strA, i
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 diff -u -p -Nr --exclude CVS xpdf/Stream.h xpdf/Stream.h
266 --- xpdf/Stream.h       2004-05-17 21:37:57.000000000 +0200
267 +++ xpdf/Stream.h       2005-12-15 13:23:59.000000000 +0100
268 @@ -233,6 +233,8 @@ public:
269  
270    ~StreamPredictor();
271  
272 +  GBool isOk() { return ok; }
273 +
274    int lookChar();
275    int getChar();
276  
277 @@ -250,6 +252,7 @@ private:
278    int rowBytes;                        // bytes per line
279    Guchar *predLine;            // line buffer
280    int predIdx;                 // current index in predLine
281 +  GBool ok;
282  };
283  
284  //------------------------------------------------------------------------