Commit 7b2c6e92 authored by Albert Astals Cid's avatar Albert Astals Cid

Fix CAN-2005-3193 related bugs

Thanks Leonard for reporting
parent a90f076a
2005-12-01 Albert Astals Cid <aacid@kde.org>
* poppler/JPXStream.cc:
* poppler/Stream.cc:
* poppler/Stream.h: Fix CAN-2005-3193 based on
ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.01pl1.patch
2005-11-28 Albert Astals Cid <aacid@kde.org>
* qt4/src/poppler-page,cc:
......
......@@ -783,7 +783,7 @@ GBool JPXStream::readCodestream(Guint len) {
int segType;
GBool haveSIZ, haveCOD, haveQCD, haveSOT;
Guint precinctSize, style;
Guint segLen, capabilities, comp, i, j, r;
Guint segLen, capabilities, nTiles, comp, i, j, r;
//----- main header
haveSIZ = haveCOD = haveQCD = haveSOT = gFalse;
......@@ -818,6 +818,13 @@ GBool JPXStream::readCodestream(Guint len) {
/ img.xTileSize;
img.nYTiles = (img.ySize - img.yTileOffset + img.yTileSize - 1)
/ img.yTileSize;
nTiles = img.nXTiles * img.nYTiles;
// check for overflow before allocating memory
if (nTiles == 0 || nTiles / img.nXTiles != img.nYTiles) {
error(getPos(), "Bad tile count in JPX SIZ marker segment");
return gFalse;
}
img.tiles = (JPXTile *)gmallocn(nTiles, sizeof(JPXTile));
img.tiles = (JPXTile *)gmallocn(img.nXTiles * img.nYTiles,
sizeof(JPXTile));
for (i = 0; i < img.nXTiles * img.nYTiles; ++i) {
......
......@@ -409,18 +409,33 @@ void ImageStream::skipLine() {
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;
nVals = width * nComps;
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() {
......@@ -1012,6 +1027,10 @@ LZWStream::LZWStream(Stream *strA, int predictor, int columns, int colors,
FilterStream(strA) {
if (predictor != 1) {
pred = new StreamPredictor(this, predictor, columns, colors, bits);
if (!pred->isOk()) {
delete pred;
pred = NULL;
}
} else {
pred = NULL;
}
......@@ -2909,6 +2928,14 @@ GBool DCTStream::readBaselineSOF() {
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 (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;
......@@ -3840,6 +3867,10 @@ FlateStream::FlateStream(Stream *strA, int predictor, int columns,
FilterStream(strA) {
if (predictor != 1) {
pred = new StreamPredictor(this, predictor, columns, colors, bits);
if (!pred->isOk()) {
delete pred;
pred = NULL;
}
} else {
pred = NULL;
}
......
......@@ -230,6 +230,8 @@ public:
~StreamPredictor();
GBool isOk() { return ok; }
int lookChar();
int getChar();
......@@ -247,6 +249,7 @@ private:
int rowBytes; // bytes per line
Guchar *predLine; // line buffer
int predIdx; // current index in predLine
GBool ok;
};
//------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment