summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Freitag <Thomas.Freitag@alfa.de>2012-09-26 14:17:00 +0200
committerAlbert Astals Cid <aacid@kde.org>2012-09-26 14:17:00 +0200
commit31874f2e065b0d68f726ef404de98f42489c80c7 (patch)
treefdc0724dbcbc26305a977e69d0f0d412b2d78284
parent81b1d9207840ec1e66eef469b29a36a8556b7265 (diff)
Less crashes in broken files
rebased patch for 1001.pdf.asan.2a.4, extends patch for 100.pdf.asan.38.2
-rw-r--r--poppler/Stream.cc100
1 files changed, 98 insertions, 2 deletions
diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index 4ce6c006..b94d9236 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -1707,7 +1707,7 @@ int CCITTFaxStream::lookChar() {
// 2-D encoding
if (nextLine2D) {
- for (i = 0; codingLine[i] < columns; ++i) {
+ for (i = 0; i < columns && codingLine[i] < columns; ++i) {
refLine[i] = codingLine[i];
}
refLine[i++] = columns;
@@ -1723,7 +1723,7 @@ int CCITTFaxStream::lookChar() {
// codingLine[a0i = 0] = refLine[b1i = 0] = 0 is possible
// exception at right edge:
// refLine[b1i] = refLine[b1i+1] = columns is possible
- while (codingLine[a0i] < columns) {
+ while (codingLine[a0i] < columns && !err) {
code1 = getTwoDimCode();
switch (code1) {
case twoDimPass:
@@ -1757,49 +1757,109 @@ int CCITTFaxStream::lookChar() {
}
while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
b1i += 2;
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
}
break;
case twoDimVertR3:
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
addPixels(refLine[b1i] + 3, blackPixels);
blackPixels ^= 1;
if (codingLine[a0i] < columns) {
++b1i;
while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
b1i += 2;
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
}
}
break;
case twoDimVertR2:
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
addPixels(refLine[b1i] + 2, blackPixels);
blackPixels ^= 1;
if (codingLine[a0i] < columns) {
++b1i;
while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
b1i += 2;
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
}
}
break;
case twoDimVertR1:
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
addPixels(refLine[b1i] + 1, blackPixels);
blackPixels ^= 1;
if (codingLine[a0i] < columns) {
++b1i;
while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
b1i += 2;
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
}
}
break;
case twoDimVert0:
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
addPixels(refLine[b1i], blackPixels);
blackPixels ^= 1;
if (codingLine[a0i] < columns) {
++b1i;
while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
b1i += 2;
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
}
}
break;
case twoDimVertL3:
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
addPixelsNeg(refLine[b1i] - 3, blackPixels);
blackPixels ^= 1;
if (codingLine[a0i] < columns) {
@@ -1810,10 +1870,22 @@ int CCITTFaxStream::lookChar() {
}
while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
b1i += 2;
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
}
}
break;
case twoDimVertL2:
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
addPixelsNeg(refLine[b1i] - 2, blackPixels);
blackPixels ^= 1;
if (codingLine[a0i] < columns) {
@@ -1824,10 +1896,22 @@ int CCITTFaxStream::lookChar() {
}
while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
b1i += 2;
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
}
}
break;
case twoDimVertL1:
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
addPixelsNeg(refLine[b1i] - 1, blackPixels);
blackPixels ^= 1;
if (codingLine[a0i] < columns) {
@@ -1838,6 +1922,12 @@ int CCITTFaxStream::lookChar() {
}
while (refLine[b1i] <= codingLine[a0i] && refLine[b1i] < columns) {
b1i += 2;
+ if (b1i > columns + 1) {
+ error(errSyntaxError, getPos(),
+ "Bad 2D code {0:04x} in CCITTFax stream", code1);
+ err = gTrue;
+ break;
+ }
}
}
break;
@@ -2021,6 +2111,12 @@ int CCITTFaxStream::lookChar() {
outputBits = 0;
if (codingLine[a0i] < columns) {
++a0i;
+ if (a0i > columns) {
+ error(errSyntaxError, getPos(),
+ "Bad bits {0:04x} in CCITTFax stream", bits);
+ err = gTrue;
+ break;
+ }
outputBits = codingLine[a0i] - codingLine[a0i - 1];
} else if (bits > 0) {
buf <<= bits;