On Thu, Dec 08, 2005 at 12:12:09AM +1100, Hamish Moffatt wrote: > On Wed, Dec 07, 2005 at 02:00:55PM +0100, Jan Niehusmann wrote: > > Ok, so you noticed that my analysis was not completely correct - while > > the woody version indeed doesn't contain JPXStream.cc (and consequently, > > the JPX stream reader bug doesn't exist in woody), the other security > > holes (in Stream.cc) do exist in woody and need patching. > > I'll work on that next, but it won't be for a day or two due to time > constraints. It looks like a bit more work that woody. You are welcome > to work on it if you like.
Well I don't have time to verify that all holes are actually closed, but the attached patch applies cleanly, and the result does compile on sarge (not tested on woody, as I don't have an installation available). Jan
diff -ur xpdf-1.00-o/xpdf/Stream.cc xpdf-1.00/xpdf/Stream.cc --- xpdf-1.00-o/xpdf/Stream.cc 2002-02-02 00:15:45.000000000 +0100 +++ xpdf-1.00/xpdf/Stream.cc 2005-12-07 15:34:21.000000000 +0100 @@ -400,18 +400,33 @@ 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() { @@ -852,6 +867,10 @@ FilterStream(strA) { if (predictor != 1) { pred = new StreamPredictor(this, predictor, columns, colors, bits); + if (!pred->isOk()) { + delete pred; + pred = NULL; + } } else { pred = NULL; } @@ -2535,6 +2554,14 @@ 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; + } length -= 6; if (prec != 8) { error(getPos(), "Bad DCT precision %d", prec); @@ -2815,6 +2842,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 -ur xpdf-1.00-o/xpdf/Stream.h xpdf-1.00/xpdf/Stream.h --- xpdf-1.00-o/xpdf/Stream.h 2002-02-02 00:15:45.000000000 +0100 +++ xpdf-1.00/xpdf/Stream.h 2005-12-07 15:34:21.000000000 +0100 @@ -214,6 +214,8 @@ ~StreamPredictor(); + GBool isOk() { return ok; } + int lookChar(); int getChar(); @@ -231,6 +233,7 @@ int rowBytes; // bytes per line Guchar *predLine; // line buffer int predIdx; // current index in predLine + GBool ok; }; //------------------------------------------------------------------------