130 lines
3.4 KiB
Diff
130 lines
3.4 KiB
Diff
|
diff -Nru cups-1.1.23.orig/pdftops/Stream.cxx cups-1.1.23/pdftops/Stream.cxx
|
||
|
--- cups-1.1.23.orig/pdftops/Stream.cxx 2005-12-14 18:14:18.000000000 +0100
|
||
|
+++ cups-1.1.23/pdftops/Stream.cxx 2005-12-14 18:20:31.000000000 +0100
|
||
|
@@ -15,6 +15,7 @@
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <stddef.h>
|
||
|
+#include <limits.h>
|
||
|
#ifndef WIN32
|
||
|
#include <unistd.h>
|
||
|
#endif
|
||
|
@@ -404,18 +405,41 @@
|
||
|
|
||
|
StreamPredictor::StreamPredictor(Stream *strA, int predictorA,
|
||
|
int widthA, int nCompsA, int nBitsA) {
|
||
|
+ int totalBits;
|
||
|
+
|
||
|
str = strA;
|
||
|
predictor = predictorA;
|
||
|
width = widthA;
|
||
|
nComps = nCompsA;
|
||
|
nBits = nBitsA;
|
||
|
+ predLine = NULL;
|
||
|
+ ok = gFalse;
|
||
|
|
||
|
+ if (width <= 0 || nComps <= 0 || nBits <= 0 ||
|
||
|
+ nComps >= INT_MAX/nBits ||
|
||
|
+ width >= INT_MAX/nComps/nBits) {
|
||
|
+ return;
|
||
|
+ }
|
||
|
nVals = width * nComps;
|
||
|
+ if (nVals + 7 <= 0) {
|
||
|
+ return;
|
||
|
+ }
|
||
|
+ totalBits = nVals * nBits;
|
||
|
+ if (totalBits == 0 ||
|
||
|
+ (totalBits / nBits) / nComps != width ||
|
||
|
+ totalBits + 7 < 0) {
|
||
|
+ return;
|
||
|
+ }
|
||
|
pixBytes = (nComps * nBits + 7) >> 3;
|
||
|
- rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes;
|
||
|
+ rowBytes = ((totalBits + 7) >> 3) + pixBytes;
|
||
|
+ if (rowBytes < 0) {
|
||
|
+ return;
|
||
|
+ }
|
||
|
predLine = (Guchar *)gmalloc(rowBytes);
|
||
|
memset(predLine, 0, rowBytes);
|
||
|
predIdx = rowBytes;
|
||
|
+
|
||
|
+ ok = gTrue;
|
||
|
}
|
||
|
|
||
|
StreamPredictor::~StreamPredictor() {
|
||
|
@@ -991,6 +1015,10 @@
|
||
|
FilterStream(strA) {
|
||
|
if (predictor != 1) {
|
||
|
pred = new StreamPredictor(this, predictor, columns, colors, bits);
|
||
|
+ if (!pred->isOk()) {
|
||
|
+ delete pred;
|
||
|
+ pred = NULL;
|
||
|
+ }
|
||
|
} else {
|
||
|
pred = NULL;
|
||
|
}
|
||
|
@@ -2891,6 +2919,10 @@
|
||
|
height = read16();
|
||
|
width = read16();
|
||
|
numComps = str->getChar();
|
||
|
+ if (numComps <= 0 || numComps > 4) {
|
||
|
+ error(getPos(), "Bad number of components in DCT stream", prec);
|
||
|
+ return gFalse;
|
||
|
+ }
|
||
|
if (prec != 8) {
|
||
|
error(getPos(), "Bad DCT precision %d", prec);
|
||
|
return gFalse;
|
||
|
@@ -2917,6 +2949,10 @@
|
||
|
height = read16();
|
||
|
width = read16();
|
||
|
numComps = str->getChar();
|
||
|
+ if (numComps <= 0 || numComps > 4) {
|
||
|
+ error(getPos(), "Bad number of components in DCT stream");
|
||
|
+ return gFalse;
|
||
|
+ }
|
||
|
if (prec != 8) {
|
||
|
error(getPos(), "Bad DCT precision %d", prec);
|
||
|
return gFalse;
|
||
|
@@ -2939,6 +2975,10 @@
|
||
|
|
||
|
length = read16() - 2;
|
||
|
scanInfo.numComps = str->getChar();
|
||
|
+ if (scanInfo.numComps <= 0 || scanInfo.numComps > 4) {
|
||
|
+ error(getPos(), "Bad number of components in DCT stream");
|
||
|
+ return gFalse;
|
||
|
+ }
|
||
|
--length;
|
||
|
if (length != 2 * scanInfo.numComps + 3) {
|
||
|
error(getPos(), "Bad DCT scan info block");
|
||
|
@@ -3249,6 +3289,10 @@
|
||
|
FilterStream(strA) {
|
||
|
if (predictor != 1) {
|
||
|
pred = new StreamPredictor(this, predictor, columns, colors, bits);
|
||
|
+ if (!pred->isOk()) {
|
||
|
+ delete pred;
|
||
|
+ pred = NULL;
|
||
|
+ }
|
||
|
} else {
|
||
|
pred = NULL;
|
||
|
}
|
||
|
diff -Nru cups-1.1.23.orig/pdftops/Stream.h cups-1.1.23/pdftops/Stream.h
|
||
|
--- cups-1.1.23.orig/pdftops/Stream.h 2005-12-14 18:14:18.000000000 +0100
|
||
|
+++ cups-1.1.23/pdftops/Stream.h 2005-12-14 18:20:31.000000000 +0100
|
||
|
@@ -231,6 +231,8 @@
|
||
|
|
||
|
~StreamPredictor();
|
||
|
|
||
|
+ GBool isOk() { return ok; }
|
||
|
+
|
||
|
int lookChar();
|
||
|
int getChar();
|
||
|
|
||
|
@@ -248,6 +250,7 @@
|
||
|
int rowBytes; // bytes per line
|
||
|
Guchar *predLine; // line buffer
|
||
|
int predIdx; // current index in predLine
|
||
|
+ GBool ok;
|
||
|
};
|
||
|
|
||
|
//------------------------------------------------------------------------
|