~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to debian/patches/kubuntu_08_xpdf2-CVE-2007-4352-5392-5393.diff.patch

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-11-07 20:29:32 UTC
  • Revision ID: james.westby@ubuntu.com-20071107202932-38fyyxtmbw3om0ki
Tags: 1:1.5.2-0ubuntu2.3
* SECURITY UPDATE: multiple xpdf based vulnerabilities
* Remotely supplied pdf files can be used to disrupt the koffice PDF
  import filter on the client machine and possibly execute arbitrary code.
* Add debian/patches/kubuntu_08_xpdf2-CVE-2007-4352-5392-5393.diff
  edits filters/kword/pdf/xpdf/xpdf/Stream.cc and .h
* References
  CVE-2007-4352
  CVE-2007-5392
  CVE-2007-5393    
  http://www.kde.org/info/security/advisory-20071107-1.txt

Show diffs side-by-side

added added

removed removed

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