From: [1] http://cgit.freedesktop.org/poppler/poppler/commit/?h=poppler-0.22&id=8b6dc55e530b2f5ede6b9dfb64aafdd1d5836492 [2] http://cgit.freedesktop.org/poppler/poppler/commit/?h=poppler-0.22&id=e14b6e9c13d35c9bd1e0c50906ace8e707816888 [3] http://cgit.freedesktop.org/poppler/poppler/commit/?h=poppler-0.22&id=0388837f01bc467045164f9ddaff787000a8caaa [4] http://cgit.freedesktop.org/poppler/poppler/commit/?h=poppler-0.22&id=957aa252912cde85d76c41e9710b33425a82b696 [5] http://cgit.freedesktop.org/poppler/poppler/commit/?h=poppler-0.22&id=bbc2d8918fe234b7ef2c480eb148943922cc0959 diff --git a/poppler/Function.cc b/poppler/Function.cc index 25e8f74..0cad9c9 100644 --- a/poppler/Function.cc +++ b/poppler/Function.cc @@ -13,7 +13,7 @@ // All changes made under the Poppler project to this file are licensed // under GPL version 2 or later // -// Copyright (C) 2006, 2008-2010 Albert Astals Cid +// Copyright (C) 2006, 2008-2010, 2013 Albert Astals Cid // Copyright (C) 2006 Jeff Muizelaar // Copyright (C) 2010 Christian Feuersänger // Copyright (C) 2011 Andrea Canciani @@ -1058,6 +1058,10 @@ void PSStack::copy(int n) { error(errSyntaxError, -1, "Stack underflow in PostScript function"); return; } + if (unlikely(sp - n > psStackSize)) { + error(errSyntaxError, -1, "Stack underflow in PostScript function"); + return; + } if (!checkOverflow(n)) { return; } diff --git a/poppler/Stream.cc b/poppler/Stream.cc index 4ce6c00..3e6c908 100644 --- a/poppler/Stream.cc +++ b/poppler/Stream.cc @@ -2288,7 +2288,8 @@ GBool CCITTFaxStream::isBinary(GBool last) { // clip [-256,511] --> [0,255] #define dctClipOffset 256 -static Guchar dctClip[768]; +#define dctClipLength 768 +static Guchar dctClip[dctClipLength]; static int dctClipInit = 0; // zig zag decode map @@ -3244,7 +3245,12 @@ void DCTStream::transformDataUnit(Gushort *quantTable, // convert to 8-bit integers for (i = 0; i < 64; ++i) { - dataOut[i] = dctClip[dctClipOffset + 128 + ((dataIn[i] + 8) >> 4)]; + const int ix = dctClipOffset + 128 + ((dataIn[i] + 8) >> 4); + if (unlikely(ix < 0 || ix >= dctClipLength)) { + dataOut[i] = 0; + } else { + dataOut[i] = dctClip[ix]; + } } } diff --git a/splash/Splash.cc b/splash/Splash.cc index e6559f4..b8863dd 100644 --- a/splash/Splash.cc +++ b/splash/Splash.cc @@ -14,7 +14,7 @@ // Copyright (C) 2005-2012 Albert Astals Cid // Copyright (C) 2005 Marco Pesenti Gritti // Copyright (C) 2010-2012 Thomas Freitag -// Copyright (C) 2010 Christian Feuersänger +// Copyright (C) 2010 Christian Feuersänger // Copyright (C) 2011, 2012 William Bader // Copyright (C) 2012 Markus Trippelsdorf // @@ -2102,11 +2102,14 @@ SplashPath *Splash::makeDashedPath(SplashPath *path) { lineDashStartOn = gTrue; lineDashStartIdx = 0; if (lineDashStartPhase > 0) { - while (lineDashStartPhase >= state->lineDash[lineDashStartIdx]) { + while (lineDashStartIdx < state->lineDashLength && lineDashStartPhase >= state->lineDash[lineDashStartIdx]) { lineDashStartOn = !lineDashStartOn; lineDashStartPhase -= state->lineDash[lineDashStartIdx]; ++lineDashStartIdx; } + if (unlikely(lineDashStartIdx == state->lineDashLength)) { + return new SplashPath(); + } } dPath = new SplashPath(); @@ -3078,6 +3081,12 @@ void Splash::scaleMaskYdXu(SplashImageMaskSource src, void *srcData, Guchar *destPtr; int yp, yq, xp, xq, yt, y, yStep, xt, x, xStep, d; int i, j; + + destPtr = dest->data; + if (destPtr == NULL) { + error(errInternal, -1, "dest->data is NULL in Splash::scaleMaskYdXu"); + return; + } // Bresenham parameters for y scale yp = srcHeight / scaledHeight; @@ -3094,7 +3103,6 @@ void Splash::scaleMaskYdXu(SplashImageMaskSource src, void *srcData, // init y scale Bresenham yt = 0; - destPtr = dest->data; for (y = 0; y < scaledHeight; ++y) { // y scale Bresenham @@ -3153,6 +3161,12 @@ void Splash::scaleMaskYuXd(SplashImageMaskSource src, void *srcData, Guchar *destPtr0, *destPtr; int yp, yq, xp, xq, yt, y, yStep, xt, x, xStep, xx, d, d0, d1; int i; + + destPtr0 = dest->data; + if (destPtr0 == NULL) { + error(errInternal, -1, "dest->data is NULL in Splash::scaleMaskYuXd"); + return; + } // Bresenham parameters for y scale yp = scaledHeight / srcHeight; @@ -3168,7 +3182,6 @@ void Splash::scaleMaskYuXd(SplashImageMaskSource src, void *srcData, // init y scale Bresenham yt = 0; - destPtr0 = dest->data; for (y = 0; y < srcHeight; ++y) { // y scale Bresenham @@ -4491,6 +4504,11 @@ void Splash::vertFlipImage(SplashBitmap *img, int width, int height, Guchar *lineBuf; Guchar *p0, *p1; int w; + + if (unlikely(img->data == NULL)) { + error(errInternal, -1, "img->data is NULL in Splash::vertFlipImage"); + return; + } w = width * nComps; lineBuf = (Guchar *)gmalloc(w);