~ubuntu-branches/ubuntu/wily/luatex/wily

« back to all changes in this revision

Viewing changes to source/libs/xpdf/xpdf-3.02-PATCHES/patch-02-pl2

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2010-04-29 00:47:19 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100429004719-o42etkqe90n97b9e
Tags: 0.60.1-1
* new upstream release, adapt build-script patch
* disable patch: upstream-epstopdf_cc_no_xpdf_patching, included upstream
* disable patch: libpoppler-0.12, not needed anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
        Official patch http://www.foolabs.com/xpdf/xpdf-3.02pl2.patch
 
2
 
 
3
        Update of xpdfVersion in xpdf-3.02/xpdf/config.h
 
4
 
 
5
diff -ur -N xpdf-3.02.orig/xpdf/Stream.cc xpdf-3.02/xpdf/Stream.cc
 
6
--- xpdf-3.02.orig/xpdf/Stream.cc       2007-08-01 10:34:31.000000000 +0200
 
7
+++ xpdf-3.02/xpdf/Stream.cc    2007-11-12 13:27:21.000000000 +0100
 
8
@@ -1243,23 +1243,26 @@
 
9
   columns = columnsA;
 
10
   if (columns < 1) {
 
11
     columns = 1;
 
12
-  }
 
13
-  if (columns + 4 <= 0) {
 
14
-    columns = INT_MAX - 4;
 
15
+  } else if (columns > INT_MAX - 2) {
 
16
+    columns = INT_MAX - 2;
 
17
   }
 
18
   rows = rowsA;
 
19
   endOfBlock = endOfBlockA;
 
20
   black = blackA;
 
21
-  refLine = (short *)gmallocn(columns + 3, sizeof(short));
 
22
-  codingLine = (short *)gmallocn(columns + 2, sizeof(short));
 
23
+  // 0 <= codingLine[0] < codingLine[1] < ... < codingLine[n] = columns
 
24
+  // ---> max codingLine size = columns + 1
 
25
+  // refLine has one extra guard entry at the end
 
26
+  // ---> max refLine size = columns + 2
 
27
+  codingLine = (int *)gmallocn(columns + 1, sizeof(int));
 
28
+  refLine = (int *)gmallocn(columns + 2, sizeof(int));
 
29
 
 
30
   eof = gFalse;
 
31
   row = 0;
 
32
   nextLine2D = encoding < 0;
 
33
   inputBits = 0;
 
34
-  codingLine[0] = 0;
 
35
-  codingLine[1] = refLine[2] = columns;
 
36
-  a0 = 1;
 
37
+  codingLine[0] = columns;
 
38
+  a0i = 0;
 
39
+  outputBits = 0;
 
40
 
 
41
   buf = EOF;
 
42
 }
 
43
@@ -1278,9 +1281,9 @@
 
44
   row = 0;
 
45
   nextLine2D = encoding < 0;
 
46
   inputBits = 0;
 
47
-  codingLine[0] = 0;
 
48
-  codingLine[1] = columns;
 
49
-  a0 = 1;
 
50
+  codingLine[0] = columns;
 
51
+  a0i = 0;
 
52
+  outputBits = 0;
 
53
   buf = EOF;
 
54
 
 
55
   // skip any initial zero bits and end-of-line marker, and get the 2D
 
56
@@ -1297,211 +1300,230 @@
 
57
   }
 
58
 }
 
59
 
 
60
+inline void CCITTFaxStream::addPixels(int a1, int blackPixels) {
 
61
+  if (a1 > codingLine[a0i]) {
 
62
+    if (a1 > columns) {
 
63
+      error(getPos(), "CCITTFax row is wrong length (%d)", a1);
 
64
+      err = gTrue;
 
65
+      a1 = columns;
 
66
+    }
 
67
+    if ((a0i & 1) ^ blackPixels) {
 
68
+      ++a0i;
 
69
+    }
 
70
+    codingLine[a0i] = a1;
 
71
+  }
 
72
+}
 
73
+
 
74
+inline void CCITTFaxStream::addPixelsNeg(int a1, int blackPixels) {
 
75
+  if (a1 > codingLine[a0i]) {
 
76
+    if (a1 > columns) {
 
77
+      error(getPos(), "CCITTFax row is wrong length (%d)", a1);
 
78
+      err = gTrue;
 
79
+      a1 = columns;
 
80
+    }
 
81
+    if ((a0i & 1) ^ blackPixels) {
 
82
+      ++a0i;
 
83
+    }
 
84
+    codingLine[a0i] = a1;
 
85
+  } else if (a1 < codingLine[a0i]) {
 
86
+    if (a1 < 0) {
 
87
+      error(getPos(), "Invalid CCITTFax code");
 
88
+      err = gTrue;
 
89
+      a1 = 0;
 
90
+    }
 
91
+    while (a0i > 0 && a1 <= codingLine[a0i - 1]) {
 
92
+      --a0i;
 
93
+    }
 
94
+    codingLine[a0i] = a1;
 
95
+  }
 
96
+}
 
97
+
 
98
 int CCITTFaxStream::lookChar() {
 
99
   short code1, code2, code3;
 
100
-  int a0New;
 
101
-  GBool err, gotEOL;
 
102
-  int ret;
 
103
-  int bits, i;
 
104
+  int b1i, blackPixels, i, bits;
 
105
+  GBool gotEOL;
 
106
 
 
107
-  // if at eof just return EOF
 
108
-  if (eof && codingLine[a0] >= columns) {
 
109
-    return EOF;
 
110
+  if (buf != EOF) {
 
111
+    return buf;
 
112
   }
 
113
 
 
114
   // read the next row
 
115
-  err = gFalse;
 
116
-  if (codingLine[a0] >= columns) {
 
117
+  if (outputBits == 0) {
 
118
+
 
119
+    // if at eof just return EOF
 
120
+    if (eof) {
 
121
+      return EOF;
 
122
+    }
 
123
+
 
124
+    err = gFalse;
 
125
 
 
126
     // 2-D encoding
 
127
     if (nextLine2D) {
 
128
-      // state:
 
129
-      //   a0New = current position in coding line (0 <= a0New <= columns)
 
130
-      //   codingLine[a0] = last change in coding line
 
131
-      //                    (black-to-white if a0 is even,
 
132
-      //                     white-to-black if a0 is odd)
 
133
-      //   refLine[b1] = next change in reference line of opposite color
 
134
-      //                 to a0
 
135
-      // invariants:
 
136
-      //   0 <= codingLine[a0] <= a0New
 
137
-      //           <= refLine[b1] <= refLine[b1+1] <= columns
 
138
-      //   0 <= a0 <= columns+1
 
139
-      //   refLine[0] = 0
 
140
-      //   refLine[n] = refLine[n+1] = columns
 
141
-      //     -- for some 1 <= n <= columns+1
 
142
-      // end condition:
 
143
-      //   0 = codingLine[0] <= codingLine[1] < codingLine[2] < ...
 
144
-      //     < codingLine[n-1] < codingLine[n] = columns
 
145
-      //     -- where 1 <= n <= columns+1
 
146
       for (i = 0; codingLine[i] < columns; ++i) {
 
147
        refLine[i] = codingLine[i];
 
148
       }
 
149
-      refLine[i] = refLine[i + 1] = columns;
 
150
-      b1 = 1;
 
151
-      a0New = codingLine[a0 = 0] = 0;
 
152
-      do {
 
153
+      refLine[i++] = columns;
 
154
+      refLine[i] = columns;
 
155
+      codingLine[0] = 0;
 
156
+      a0i = 0;
 
157
+      b1i = 0;
 
158
+      blackPixels = 0;
 
159
+      // invariant:
 
160
+      // refLine[b1i-1] <= codingLine[a0i] < refLine[b1i] < refLine[b1i+1]
 
161
+      //                                                             <= columns
 
162
+      // exception at left edge:
 
163
+      //   codingLine[a0i = 0] = refLine[b1i = 0] = 0 is possible
 
164
+      // exception at right edge:
 
165
+      //   refLine[b1i] = refLine[b1i+1] = columns is possible
 
166
+      while (codingLine[a0i] < columns) {
 
167
        code1 = getTwoDimCode();
 
168
        switch (code1) {
 
169
        case twoDimPass:
 
170
-         if (refLine[b1] < columns) {
 
171
-           a0New = refLine[b1 + 1];
 
172
-           b1 += 2;
 
173
+         addPixels(refLine[b1i + 1], blackPixels);
 
174
+         if (refLine[b1i + 1] < columns) {
 
175
+           b1i += 2;
 
176
          }
 
177
          break;
 
178
        case twoDimHoriz:
 
179
-         if ((a0 & 1) == 0) {
 
180
-           code1 = code2 = 0;
 
181
+         code1 = code2 = 0;
 
182
+         if (blackPixels) {
 
183
            do {
 
184
-             code1 += code3 = getWhiteCode();
 
185
+             code1 += code3 = getBlackCode();
 
186
            } while (code3 >= 64);
 
187
            do {
 
188
-             code2 += code3 = getBlackCode();
 
189
+             code2 += code3 = getWhiteCode();
 
190
            } while (code3 >= 64);
 
191
          } else {
 
192
-           code1 = code2 = 0;
 
193
            do {
 
194
-             code1 += code3 = getBlackCode();
 
195
+             code1 += code3 = getWhiteCode();
 
196
            } while (code3 >= 64);
 
197
            do {
 
198
-             code2 += code3 = getWhiteCode();
 
199
+             code2 += code3 = getBlackCode();
 
200
            } while (code3 >= 64);
 
201
          }
 
202
-         if (code1 > 0 || code2 > 0) {
 
203
-           if (a0New + code1 <= columns) {
 
204
-             codingLine[a0 + 1] = a0New + code1;
 
205
-           } else {
 
206
-             codingLine[a0 + 1] = columns;
 
207
-           }
 
208
-           ++a0;
 
209
-           if (codingLine[a0] + code2 <= columns) {
 
210
-             codingLine[a0 + 1] = codingLine[a0] + code2;
 
211
-           } else {
 
212
-             codingLine[a0 + 1] = columns;
 
213
-           }
 
214
-           ++a0;
 
215
-           a0New = codingLine[a0];
 
216
-           while (refLine[b1] <= a0New && refLine[b1] < columns) {
 
217
-             b1 += 2;
 
218
+         addPixels(codingLine[a0i] + code1, blackPixels);
 
219
+         if (codingLine[a0i] < columns) {
 
220
+           addPixels(codingLine[a0i] + code2, blackPixels ^ 1);
 
221
+         }
 
222
+         while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
 
223
+           b1i += 2;
 
224
+         }
 
225
+         break;
 
226
+       case twoDimVertR3:
 
227
+         addPixels(refLine[b1i] + 3, blackPixels);
 
228
+         blackPixels ^= 1;
 
229
+         if (codingLine[a0i] < columns) {
 
230
+           ++b1i;
 
231
+           while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
 
232
+             b1i += 2;
 
233
            }
 
234
          }
 
235
          break;
 
236
-       case twoDimVert0:
 
237
-         if (refLine[b1] < columns) {
 
238
-           a0New = codingLine[++a0] = refLine[b1];
 
239
-           ++b1;
 
240
-           while (refLine[b1] <= a0New && refLine[b1] < columns) {
 
241
-             b1 += 2;
 
242
+       case twoDimVertR2:
 
243
+         addPixels(refLine[b1i] + 2, blackPixels);
 
244
+         blackPixels ^= 1;
 
245
+         if (codingLine[a0i] < columns) {
 
246
+           ++b1i;
 
247
+           while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
 
248
+             b1i += 2;
 
249
            }
 
250
-         } else {
 
251
-           a0New = codingLine[++a0] = columns;
 
252
          }
 
253
          break;
 
254
        case twoDimVertR1:
 
255
-         if (refLine[b1] + 1 < columns) {
 
256
-           a0New = codingLine[++a0] = refLine[b1] + 1;
 
257
-           ++b1;
 
258
-           while (refLine[b1] <= a0New && refLine[b1] < columns) {
 
259
-             b1 += 2;
 
260
+         addPixels(refLine[b1i] + 1, blackPixels);
 
261
+         blackPixels ^= 1;
 
262
+         if (codingLine[a0i] < columns) {
 
263
+           ++b1i;
 
264
+           while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
 
265
+             b1i += 2;
 
266
            }
 
267
-         } else {
 
268
-           a0New = codingLine[++a0] = columns;
 
269
          }
 
270
          break;
 
271
-       case twoDimVertL1:
 
272
-         if (refLine[b1] - 1 > a0New || (a0 == 0 && refLine[b1] == 1)) {
 
273
-           a0New = codingLine[++a0] = refLine[b1] - 1;
 
274
-           --b1;
 
275
-           while (refLine[b1] <= a0New && refLine[b1] < columns) {
 
276
-             b1 += 2;
 
277
+       case twoDimVert0:
 
278
+         addPixels(refLine[b1i], blackPixels);
 
279
+         blackPixels ^= 1;
 
280
+         if (codingLine[a0i] < columns) {
 
281
+           ++b1i;
 
282
+           while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
 
283
+             b1i += 2;
 
284
            }
 
285
          }
 
286
          break;
 
287
-       case twoDimVertR2:
 
288
-         if (refLine[b1] + 2 < columns) {
 
289
-           a0New = codingLine[++a0] = refLine[b1] + 2;
 
290
-           ++b1;
 
291
-           while (refLine[b1] <= a0New && refLine[b1] < columns) {
 
292
-             b1 += 2;
 
293
+       case twoDimVertL3:
 
294
+         addPixelsNeg(refLine[b1i] - 3, blackPixels);
 
295
+         blackPixels ^= 1;
 
296
+         if (codingLine[a0i] < columns) {
 
297
+           if (b1i > 0) {
 
298
+             --b1i;
 
299
+           } else {
 
300
+             ++b1i;
 
301
+           }
 
302
+           while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
 
303
+             b1i += 2;
 
304
            }
 
305
-         } else {
 
306
-           a0New = codingLine[++a0] = columns;
 
307
          }
 
308
          break;
 
309
        case twoDimVertL2:
 
310
-         if (refLine[b1] - 2 > a0New || (a0 == 0 && refLine[b1] == 2)) {
 
311
-           a0New = codingLine[++a0] = refLine[b1] - 2;
 
312
-           --b1;
 
313
-           while (refLine[b1] <= a0New && refLine[b1] < columns) {
 
314
-             b1 += 2;
 
315
+         addPixelsNeg(refLine[b1i] - 2, blackPixels);
 
316
+         blackPixels ^= 1;
 
317
+         if (codingLine[a0i] < columns) {
 
318
+           if (b1i > 0) {
 
319
+             --b1i;
 
320
+           } else {
 
321
+             ++b1i;
 
322
            }
 
323
-         }
 
324
-         break;
 
325
-       case twoDimVertR3:
 
326
-         if (refLine[b1] + 3 < columns) {
 
327
-           a0New = codingLine[++a0] = refLine[b1] + 3;
 
328
-           ++b1;
 
329
-           while (refLine[b1] <= a0New && refLine[b1] < columns) {
 
330
-             b1 += 2;
 
331
+           while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
 
332
+             b1i += 2;
 
333
            }
 
334
-         } else {
 
335
-           a0New = codingLine[++a0] = columns;
 
336
          }
 
337
          break;
 
338
-       case twoDimVertL3:
 
339
-         if (refLine[b1] - 3 > a0New || (a0 == 0 && refLine[b1] == 3)) {
 
340
-           a0New = codingLine[++a0] = refLine[b1] - 3;
 
341
-           --b1;
 
342
-           while (refLine[b1] <= a0New && refLine[b1] < columns) {
 
343
-             b1 += 2;
 
344
+       case twoDimVertL1:
 
345
+         addPixelsNeg(refLine[b1i] - 1, blackPixels);
 
346
+         blackPixels ^= 1;
 
347
+         if (codingLine[a0i] < columns) {
 
348
+           if (b1i > 0) {
 
349
+             --b1i;
 
350
+           } else {
 
351
+             ++b1i;
 
352
+           }
 
353
+           while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
 
354
+             b1i += 2;
 
355
            }
 
356
          }
 
357
          break;
 
358
        case EOF:
 
359
+         addPixels(columns, 0);
 
360
          eof = gTrue;
 
361
-         codingLine[a0 = 0] = columns;
 
362
-         return EOF;
 
363
+         break;
 
364
        default:
 
365
          error(getPos(), "Bad 2D code %04x in CCITTFax stream", code1);
 
366
+         addPixels(columns, 0);
 
367
          err = gTrue;
 
368
          break;
 
369
        }
 
370
-      } while (codingLine[a0] < columns);
 
371
+      }
 
372
 
 
373
     // 1-D encoding
 
374
     } else {
 
375
-      codingLine[a0 = 0] = 0;
 
376
-      while (1) {
 
377
+      codingLine[0] = 0;
 
378
+      a0i = 0;
 
379
+      blackPixels = 0;
 
380
+      while (codingLine[a0i] < columns) {
 
381
        code1 = 0;
 
382
-       do {
 
383
-         code1 += code3 = getWhiteCode();
 
384
-       } while (code3 >= 64);
 
385
-       codingLine[a0+1] = codingLine[a0] + code1;
 
386
-       ++a0;
 
387
-       if (codingLine[a0] >= columns) {
 
388
-         break;
 
389
-       }
 
390
-       code2 = 0;
 
391
-       do {
 
392
-         code2 += code3 = getBlackCode();
 
393
-       } while (code3 >= 64);
 
394
-       codingLine[a0+1] = codingLine[a0] + code2;
 
395
-       ++a0;
 
396
-       if (codingLine[a0] >= columns) {
 
397
-         break;
 
398
+       if (blackPixels) {
 
399
+         do {
 
400
+           code1 += code3 = getBlackCode();
 
401
+         } while (code3 >= 64);
 
402
+       } else {
 
403
+         do {
 
404
+           code1 += code3 = getWhiteCode();
 
405
+         } while (code3 >= 64);
 
406
        }
 
407
+       addPixels(codingLine[a0i] + code1, blackPixels);
 
408
+       blackPixels ^= 1;
 
409
       }
 
410
     }
 
411
 
 
412
-    if (codingLine[a0] != columns) {
 
413
-      error(getPos(), "CCITTFax row is wrong length (%d)", codingLine[a0]);
 
414
-      // force the row to be the correct length
 
415
-      while (codingLine[a0] > columns) {
 
416
-       --a0;
 
417
-      }
 
418
-      codingLine[++a0] = columns;
 
419
-      err = gTrue;
 
420
-    }
 
421
-
 
422
     // byte-align the row
 
423
     if (byteAlign) {
 
424
       inputBits &= ~7;
 
425
@@ -1560,14 +1582,17 @@
 
426
     // this if we know the stream contains end-of-line markers because
 
427
     // the "just plow on" technique tends to work better otherwise
 
428
     } else if (err && endOfLine) {
 
429
-      do {
 
430
+      while (1) {
 
431
+       code1 = lookBits(13);
 
432
        if (code1 == EOF) {
 
433
          eof = gTrue;
 
434
          return EOF;
 
435
        }
 
436
+       if ((code1 >> 1) == 0x001) {
 
437
+         break;
 
438
+       }
 
439
        eatBits(1);
 
440
-       code1 = lookBits(13);
 
441
-      } while ((code1 >> 1) != 0x001);
 
442
+      }
 
443
       eatBits(12); 
 
444
       if (encoding > 0) {
 
445
        eatBits(1);
 
446
@@ -1575,11 +1600,11 @@
 
447
       }
 
448
     }
 
449
 
 
450
-    a0 = 0;
 
451
-    outputBits = codingLine[1] - codingLine[0];
 
452
-    if (outputBits == 0) {
 
453
-      a0 = 1;
 
454
-      outputBits = codingLine[2] - codingLine[1];
 
455
+    // set up for output
 
456
+    if (codingLine[0] > 0) {
 
457
+      outputBits = codingLine[a0i = 0];
 
458
+    } else {
 
459
+      outputBits = codingLine[a0i = 1];
 
460
     }
 
461
 
 
462
     ++row;
 
463
@@ -1587,39 +1612,43 @@
 
464
 
 
465
   // get a byte
 
466
   if (outputBits >= 8) {
 
467
-    ret = ((a0 & 1) == 0) ? 0xff : 0x00;
 
468
-    if ((outputBits -= 8) == 0) {
 
469
-      ++a0;
 
470
-      if (codingLine[a0] < columns) {
 
471
-       outputBits = codingLine[a0 + 1] - codingLine[a0];
 
472
-      }
 
473
+    buf = (a0i & 1) ? 0x00 : 0xff;
 
474
+    outputBits -= 8;
 
475
+    if (outputBits == 0 && codingLine[a0i] < columns) {
 
476
+      ++a0i;
 
477
+      outputBits = codingLine[a0i] - codingLine[a0i - 1];
 
478
     }
 
479
   } else {
 
480
     bits = 8;
 
481
-    ret = 0;
 
482
+    buf = 0;
 
483
     do {
 
484
       if (outputBits > bits) {
 
485
-       i = bits;
 
486
-       bits = 0;
 
487
-       if ((a0 & 1) == 0) {
 
488
-         ret |= 0xff >> (8 - i);
 
489
+       buf <<= bits;
 
490
+       if (!(a0i & 1)) {
 
491
+         buf |= 0xff >> (8 - bits);
 
492
        }
 
493
-       outputBits -= i;
 
494
+       outputBits -= bits;
 
495
+       bits = 0;
 
496
       } else {
 
497
-       i = outputBits;
 
498
-       bits -= outputBits;
 
499
-       if ((a0 & 1) == 0) {
 
500
-         ret |= (0xff >> (8 - i)) << bits;
 
501
+       buf <<= outputBits;
 
502
+       if (!(a0i & 1)) {
 
503
+         buf |= 0xff >> (8 - outputBits);
 
504
        }
 
505
+       bits -= outputBits;
 
506
        outputBits = 0;
 
507
-       ++a0;
 
508
-       if (codingLine[a0] < columns) {
 
509
-         outputBits = codingLine[a0 + 1] - codingLine[a0];
 
510
+       if (codingLine[a0i] < columns) {
 
511
+         ++a0i;
 
512
+         outputBits = codingLine[a0i] - codingLine[a0i - 1];
 
513
+       } else if (bits > 0) {
 
514
+         buf <<= bits;
 
515
+         bits = 0;
 
516
        }
 
517
       }
 
518
-    } while (bits > 0 && codingLine[a0] < columns);
 
519
+    } while (bits);
 
520
+  }
 
521
+  if (black) {
 
522
+    buf ^= 0xff;
 
523
   }
 
524
-  buf = black ? (ret ^ 0xff) : ret;
 
525
   return buf;
 
526
 }
 
527
 
 
528
@@ -1661,6 +1690,9 @@
 
529
   code = 0; // make gcc happy
 
530
   if (endOfBlock) {
 
531
     code = lookBits(12);
 
532
+    if (code == EOF) {
 
533
+      return 1;
 
534
+    }
 
535
     if ((code >> 5) == 0) {
 
536
       p = &whiteTab1[code];
 
537
     } else {
 
538
@@ -1673,6 +1705,9 @@
 
539
   } else {
 
540
     for (n = 1; n <= 9; ++n) {
 
541
       code = lookBits(n);
 
542
+      if (code == EOF) {
 
543
+       return 1;
 
544
+      }
 
545
       if (n < 9) {
 
546
        code <<= 9 - n;
 
547
       }
 
548
@@ -1684,6 +1719,9 @@
 
549
     }
 
550
     for (n = 11; n <= 12; ++n) {
 
551
       code = lookBits(n);
 
552
+      if (code == EOF) {
 
553
+       return 1;
 
554
+      }
 
555
       if (n < 12) {
 
556
        code <<= 12 - n;
 
557
       }
 
558
@@ -1709,9 +1747,12 @@
 
559
   code = 0; // make gcc happy
 
560
   if (endOfBlock) {
 
561
     code = lookBits(13);
 
562
+    if (code == EOF) {
 
563
+      return 1;
 
564
+    }
 
565
     if ((code >> 7) == 0) {
 
566
       p = &blackTab1[code];
 
567
-    } else if ((code >> 9) == 0) {
 
568
+    } else if ((code >> 9) == 0 && (code >> 7) != 0) {
 
569
       p = &blackTab2[(code >> 1) - 64];
 
570
     } else {
 
571
       p = &blackTab3[code >> 7];
 
572
@@ -1723,6 +1764,9 @@
 
573
   } else {
 
574
     for (n = 2; n <= 6; ++n) {
 
575
       code = lookBits(n);
 
576
+      if (code == EOF) {
 
577
+       return 1;
 
578
+      }
 
579
       if (n < 6) {
 
580
        code <<= 6 - n;
 
581
       }
 
582
@@ -1734,6 +1778,9 @@
 
583
     }
 
584
     for (n = 7; n <= 12; ++n) {
 
585
       code = lookBits(n);
 
586
+      if (code == EOF) {
 
587
+       return 1;
 
588
+      }
 
589
       if (n < 12) {
 
590
        code <<= 12 - n;
 
591
       }
 
592
@@ -1747,6 +1794,9 @@
 
593
     }
 
594
     for (n = 10; n <= 13; ++n) {
 
595
       code = lookBits(n);
 
596
+      if (code == EOF) {
 
597
+       return 1;
 
598
+      }
 
599
       if (n < 13) {
 
600
        code <<= 13 - n;
 
601
       }
 
602
@@ -1961,6 +2011,12 @@
 
603
     // allocate a buffer for the whole image
 
604
     bufWidth = ((width + mcuWidth - 1) / mcuWidth) * mcuWidth;
 
605
     bufHeight = ((height + mcuHeight - 1) / mcuHeight) * mcuHeight;
 
606
+    if (bufWidth <= 0 || bufHeight <= 0 ||
 
607
+       bufWidth > INT_MAX / bufWidth / (int)sizeof(int)) {
 
608
+      error(getPos(), "Invalid image size in DCT stream");
 
609
+      y = height;
 
610
+      return;
 
611
+    }
 
612
     for (i = 0; i < numComps; ++i) {
 
613
       frameBuf[i] = (int *)gmallocn(bufWidth * bufHeight, sizeof(int));
 
614
       memset(frameBuf[i], 0, bufWidth * bufHeight * sizeof(int));
 
615
@@ -3036,6 +3092,11 @@
 
616
   }
 
617
   scanInfo.firstCoeff = str->getChar();
 
618
   scanInfo.lastCoeff = str->getChar();
 
619
+  if (scanInfo.firstCoeff < 0 || scanInfo.lastCoeff > 63 ||
 
620
+      scanInfo.firstCoeff > scanInfo.lastCoeff) {
 
621
+    error(getPos(), "Bad DCT coefficient numbers in scan info block");
 
622
+    return gFalse;
 
623
+  }
 
624
   c = str->getChar();
 
625
   scanInfo.ah = (c >> 4) & 0x0f;
 
626
   scanInfo.al = c & 0x0f;
 
627
diff -ur -N xpdf-3.02.orig/xpdf/Stream.h xpdf-3.02/xpdf/Stream.h
 
628
--- xpdf-3.02.orig/xpdf/Stream.h        2007-02-27 23:05:52.000000000 +0100
 
629
+++ xpdf-3.02/xpdf/Stream.h     2007-11-12 13:27:21.000000000 +0100
 
630
@@ -528,13 +528,15 @@
 
631
   int row;                     // current row
 
632
   int inputBuf;                        // input buffer
 
633
   int inputBits;               // number of bits in input buffer
 
634
-  short *refLine;              // reference line changing elements
 
635
-  int b1;                      // index into refLine
 
636
-  short *codingLine;           // coding line changing elements
 
637
-  int a0;                      // index into codingLine
 
638
+  int *codingLine;             // coding line changing elements
 
639
+  int *refLine;                        // reference line changing elements
 
640
+  int a0i;                     // index into codingLine
 
641
+  GBool err;                   // error on current line
 
642
   int outputBits;              // remaining ouput bits
 
643
   int buf;                     // character buffer
 
644
 
 
645
+  void addPixels(int a1, int black);
 
646
+  void addPixelsNeg(int a1, int black);
 
647
   short getTwoDimCode();
 
648
   short getWhiteCode();
 
649
   short getBlackCode();
 
650
diff -ur -N xpdf-3.02.orig/xpdf/config.h xpdf-3.02/xpdf/config.h
 
651
--- xpdf-3.02.orig/xpdf/config.h        2007-08-01 10:34:31.000000000 +0200
 
652
+++ xpdf-3.02/xpdf/config.h     2007-11-12 13:27:21.000000000 +0100
 
653
@@ -17,7 +17,7 @@
 
654
 //------------------------------------------------------------------------
 
655
 
 
656
 // xpdf version
 
657
-#define xpdfVersion          "3.02pl1"
 
658
+#define xpdfVersion          "3.02pl2"
 
659
 #define xpdfVersionNum       3.02
 
660
 #define xpdfMajorVersion     3
 
661
 #define xpdfMinorVersion     2