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
6
//------------------------------------------------------------------------
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 @@
14
return (inputBuf >> (inputBits - n)) & (0xffff >> (16 - n));
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;
27
+ } else if (columns > (INT_MAX - 2)/sizeof(int)) {
28
+ columns = (INT_MAX - 2)/sizeof(int);
31
+ endOfBlock = endOfBlockA;
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));
42
+ nextLine2D = encoding < 0;
44
+ codingLine[0] = columns;
51
+CCITTFaxStream::~CCITTFaxStream() {
57
+void CCITTFaxStream::reset() {
63
+ nextLine2D = encoding < 0;
65
+ codingLine[0] = columns;
70
+ // skip any initial zero bits and end-of-line marker, and get the 2D
72
+ while ((code1 = lookBits(12)) == 0) {
75
+ if (code1 == 0x001) {
79
+ nextLine2D = !lookBits(1);
84
+inline void CCITTFaxStream::addPixels(int a1, int blackPixels) {
85
+ if (a1 > codingLine[a0i]) {
87
+ error(getPos(), "CCITTFax row is wrong length (%d)", a1);
91
+ if ((a0i & 1) ^ blackPixels) {
94
+ codingLine[a0i] = a1;
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);
105
+ if ((a0i & 1) ^ blackPixels) {
108
+ codingLine[a0i] = a1;
109
+ } else if (a1 < codingLine[a0i]) {
111
+ error(getPos(), "Invalid CCITTFax code");
115
+ while (a0i > 0 && a1 <= codingLine[a0i - 1]) {
118
+ codingLine[a0i] = a1;
122
+int CCITTFaxStream::lookChar() {
123
+ short code1, code2, code3;
124
+ int b1i, blackPixels, i, bits;
131
+ // read the next row
132
+ if (outputBits == 0) {
134
+ // if at eof just return EOF
143
+ for (i = 0; codingLine[i] < columns; ++i) {
144
+ refLine[i] = codingLine[i];
146
+ refLine[i++] = columns;
147
+ refLine[i] = columns;
153
+ // refLine[b1i-1] <= codingLine[a0i] < refLine[b1i] < refLine[b1i+1]
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();
163
+ addPixels(refLine[b1i + 1], blackPixels);
164
+ if (refLine[b1i + 1] < columns) {
172
+ code1 += code3 = getBlackCode();
173
+ } while (code3 >= 64);
175
+ code2 += code3 = getWhiteCode();
176
+ } while (code3 >= 64);
179
+ code1 += code3 = getWhiteCode();
180
+ } while (code3 >= 64);
182
+ code2 += code3 = getBlackCode();
183
+ } while (code3 >= 64);
185
+ addPixels(codingLine[a0i] + code1, blackPixels);
186
+ if (codingLine[a0i] < columns) {
187
+ addPixels(codingLine[a0i] + code2, blackPixels ^ 1);
189
+ while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
194
+ addPixels(refLine[b1i] + 3, blackPixels);
196
+ if (codingLine[a0i] < columns) {
198
+ while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
204
+ addPixels(refLine[b1i] + 2, blackPixels);
206
+ if (codingLine[a0i] < columns) {
208
+ while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
214
+ addPixels(refLine[b1i] + 1, blackPixels);
216
+ if (codingLine[a0i] < columns) {
218
+ while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
224
+ addPixels(refLine[b1i], blackPixels);
226
+ if (codingLine[a0i] < columns) {
228
+ while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
234
+ addPixelsNeg(refLine[b1i] - 3, blackPixels);
236
+ if (codingLine[a0i] < columns) {
242
+ while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
248
+ addPixelsNeg(refLine[b1i] - 2, blackPixels);
250
+ if (codingLine[a0i] < columns) {
256
+ while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
262
+ addPixelsNeg(refLine[b1i] - 1, blackPixels);
264
+ if (codingLine[a0i] < columns) {
270
+ while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
276
+ addPixels(columns, 0);
280
+ error(getPos(), "Bad 2D code %04x in CCITTFax stream", code1);
281
+ addPixels(columns, 0);
292
+ while (codingLine[a0i] < columns) {
296
+ code1 += code3 = getBlackCode();
297
+ } while (code3 >= 64);
300
+ code1 += code3 = getWhiteCode();
301
+ } while (code3 >= 64);
303
+ addPixels(codingLine[a0i] + code1, blackPixels);
308
+ // byte-align the row
313
+ // check for end-of-line marker, skipping over any extra zero bits
315
+ if (!endOfBlock && row == rows - 1) {
318
+ code1 = lookBits(12);
319
+ while (code1 == 0) {
321
+ code1 = lookBits(12);
323
+ if (code1 == 0x001) {
326
+ } else if (code1 == EOF) {
331
+ // get 2D encoding tag
332
+ if (!eof && encoding > 0) {
333
+ nextLine2D = !lookBits(1);
337
+ // check for end-of-block marker
338
+ if (endOfBlock && gotEOL) {
339
+ code1 = lookBits(12);
340
+ if (code1 == 0x001) {
342
+ if (encoding > 0) {
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");
353
+ if (encoding > 0) {
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) {
367
+ code1 = lookBits(13);
368
+ if (code1 == EOF) {
372
+ if ((code1 >> 1) == 0x001) {
378
+ if (encoding > 0) {
380
+ nextLine2D = !(code1 & 1);
384
+ // set up for output
385
+ if (codingLine[0] > 0) {
386
+ outputBits = codingLine[a0i = 0];
388
+ outputBits = codingLine[a0i = 1];
395
+ if (outputBits >= 8) {
396
+ buf = (a0i & 1) ? 0x00 : 0xff;
398
+ if (outputBits == 0 && codingLine[a0i] < columns) {
400
+ outputBits = codingLine[a0i] - codingLine[a0i - 1];
406
+ if (outputBits > bits) {
409
+ buf |= 0xff >> (8 - bits);
411
+ outputBits -= bits;
414
+ buf <<= outputBits;
416
+ buf |= 0xff >> (8 - outputBits);
418
+ bits -= outputBits;
420
+ if (codingLine[a0i] < columns) {
422
+ outputBits = codingLine[a0i] - codingLine[a0i - 1];
423
+ } else if (bits > 0) {
436
+short CCITTFaxStream::getTwoDimCode() {
441
+ code = 0; // make gcc happy
443
+ code = lookBits(7);
444
+ p = &twoDimTab1[code];
450
+ for (n = 1; n <= 7; ++n) {
451
+ code = lookBits(n);
455
+ p = &twoDimTab1[code];
456
+ if (p->bits == n) {
462
+ error(getPos(), "Bad two dim code (%04x) in CCITTFax stream", code);
466
+short CCITTFaxStream::getWhiteCode() {
471
+ code = 0; // make gcc happy
473
+ code = lookBits(12);
477
+ if ((code >> 5) == 0) {
478
+ p = &whiteTab1[code];
480
+ p = &whiteTab2[code >> 3];
487
+ for (n = 1; n <= 9; ++n) {
488
+ code = lookBits(n);
495
+ p = &whiteTab2[code];
496
+ if (p->bits == n) {
501
+ for (n = 11; n <= 12; ++n) {
502
+ code = lookBits(n);
509
+ p = &whiteTab1[code];
510
+ if (p->bits == n) {
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
523
+short CCITTFaxStream::getBlackCode() {
528
+ code = 0; // make gcc happy
530
+ code = lookBits(13);
534
+ if ((code >> 7) == 0) {
535
+ p = &blackTab1[code];
536
+ } else if ((code >> 9) == 0 && (code >> 7) != 0) {
537
+ p = &blackTab2[(code >> 1) - 64];
539
+ p = &blackTab3[code >> 7];
546
+ for (n = 2; n <= 6; ++n) {
547
+ code = lookBits(n);
554
+ p = &blackTab3[code];
555
+ if (p->bits == n) {
560
+ for (n = 7; n <= 12; ++n) {
561
+ code = lookBits(n);
569
+ p = &blackTab2[code - 64];
570
+ if (p->bits == n) {
576
+ for (n = 10; n <= 13; ++n) {
577
+ code = lookBits(n);
584
+ p = &blackTab1[code];
585
+ if (p->bits == n) {
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
598
+short CCITTFaxStream::lookBits(int n) {
601
+ while (inputBits < n) {
602
+ if ((c = str->getChar()) == EOF) {
603
+ if (inputBits == 0) {
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));
612
+ inputBuf = (inputBuf << 8) + c;
615
+ return (inputBuf >> (inputBits - n)) & (0xffff >> (16 - n));
620
GString *CCITTFaxStream::getPSFilter(const char *indent) {
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");
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 @@
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");
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
663
int outputBits; // remaining output bits
664
int buf; // character buffer
666
+ void addPixels(int a1, int black);
667
+ void addPixelsNeg(int a1, int black);
669
short getTwoDimCode();
670
short getWhiteCode();
671
short getBlackCode();