1 Adaptation of xpdf 3.02pl4 to kpdf.
3 2009-11-12 Martin von Gagern
5 ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.02pl4.patch
6 https://bugs.gentoo.org/290470
7 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3603
8 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3604
9 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3606
10 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3608
12 Index: kpdf-3.5.10/kpdf/xpdf/splash/Splash.cc
13 ===================================================================
14 --- kpdf-3.5.10.orig/kpdf/xpdf/splash/Splash.cc
15 +++ kpdf-3.5.10/kpdf/xpdf/splash/Splash.cc
22 #include "SplashErrorCodes.h"
23 #include "SplashMath.h"
24 @@ -1937,7 +1938,10 @@ SplashError Splash::fillImageMask(Splash
27 // allocate pixel buffer
28 - pixBuf = (SplashColorPtr)gmalloc((yp + 1) * w);
29 + if (yp < 0 || yp > INT_MAX - 1) {
30 + return splashErrBadArg;
32 + pixBuf = (SplashColorPtr)gmallocn(yp + 1, w);
34 // initialize the pixel pipe
35 pipeInit(&pipe, 0, 0, state->fillPattern, NULL, state->fillAlpha,
36 @@ -2233,9 +2237,12 @@ SplashError Splash::drawImage(SplashImag
39 // allocate pixel buffers
40 - colorBuf = (SplashColorPtr)gmalloc((yp + 1) * w * nComps);
41 + if (yp < 0 || yp > INT_MAX - 1 || w > INT_MAX / nComps) {
42 + return splashErrBadArg;
44 + colorBuf = (SplashColorPtr)gmallocn(yp + 1, w * nComps);
46 - alphaBuf = (Guchar *)gmalloc((yp + 1) * w);
47 + alphaBuf = (Guchar *)gmallocn(yp + 1, w);
51 Index: kpdf-3.5.10/kpdf/xpdf/splash/SplashBitmap.cc
52 ===================================================================
53 --- kpdf-3.5.10.orig/kpdf/xpdf/splash/SplashBitmap.cc
54 +++ kpdf-3.5.10/kpdf/xpdf/splash/SplashBitmap.cc
61 #include "SplashErrorCodes.h"
62 #include "SplashBitmap.h"
63 @@ -27,30 +28,48 @@ SplashBitmap::SplashBitmap(int widthA, i
67 - rowSize = (width + 7) >> 3;
69 + rowSize = (width + 7) >> 3;
84 - rowSize = width * 3;
85 + if (width > 0 && width <= INT_MAX / 3) {
86 + rowSize = width * 3;
93 - rowSize = width * 4;
94 + if (width > 0 && width <= INT_MAX / 4) {
95 + rowSize = width * 4;
102 - rowSize += rowPad - 1;
103 - rowSize -= rowSize % rowPad;
104 - data = (SplashColorPtr)gmallocn(rowSize, height);
106 + rowSize += rowPad - 1;
107 + rowSize -= rowSize % rowPad;
109 + data = (SplashColorPtr)gmallocn(height, rowSize);
111 data += (height - 1) * rowSize;
115 - alpha = (Guchar *)gmalloc(width * height);
116 + alpha = (Guchar *)gmallocn(width, height);
120 Index: kpdf-3.5.10/kpdf/xpdf/splash/SplashErrorCodes.h
121 ===================================================================
122 --- kpdf-3.5.10.orig/kpdf/xpdf/splash/SplashErrorCodes.h
123 +++ kpdf-3.5.10/kpdf/xpdf/splash/SplashErrorCodes.h
126 #define splashErrZeroImage 9 // image of 0x0
128 +#define splashErrBadArg 9 // bad argument
131 Index: kpdf-3.5.10/kpdf/xpdf/xpdf/PSOutputDev.cc
132 ===================================================================
133 --- kpdf-3.5.10.orig/kpdf/xpdf/xpdf/PSOutputDev.cc
134 +++ kpdf-3.5.10/kpdf/xpdf/xpdf/PSOutputDev.cc
135 @@ -4386,7 +4386,7 @@ void PSOutputDev::doImageL1Sep(GfxImageC
136 width, -height, height);
138 // allocate a line buffer
139 - lineBuf = (Guchar *)gmalloc(4 * width);
140 + lineBuf = (Guchar *)gmallocn(width, 4);
142 // set up to process the data stream
143 imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(),
144 Index: kpdf-3.5.10/kpdf/xpdf/xpdf/Stream.cc
145 ===================================================================
146 --- kpdf-3.5.10.orig/kpdf/xpdf/xpdf/Stream.cc
147 +++ kpdf-3.5.10/kpdf/xpdf/xpdf/Stream.cc
148 @@ -323,6 +323,10 @@ ImageStream::ImageStream(Stream *strA, i
152 + if (width > INT_MAX / nComps) {
153 + // force a call to gmallocn(-1,...), which will throw an exception
156 imgLine = (Guchar *)gmallocn(imgLineSize, sizeof(Guchar));
159 Index: kpdf-3.5.10/kpdf/xpdf/xpdf/XRef.cc
160 ===================================================================
161 --- kpdf-3.5.10.orig/kpdf/xpdf/xpdf/XRef.cc
162 +++ kpdf-3.5.10/kpdf/xpdf/xpdf/XRef.cc
163 @@ -52,6 +52,8 @@ public:
165 ObjectStream(XRef *xref, int objStrNumA);
167 + GBool isOk() { return ok; }
171 // Return the object number of this object stream.
172 @@ -67,6 +69,7 @@ private:
173 int nObjects; // number of objects in the stream
174 Object *objs; // the objects (length = nObjects)
175 int *objNums; // the object numbers (length = nObjects)
179 ObjectStream::ObjectStream(XRef *xref, int objStrNumA) {
180 @@ -80,6 +83,7 @@ ObjectStream::ObjectStream(XRef *xref, i
186 if (!xref->fetch(objStrNum, 0, &objStr)->isStream()) {
188 @@ -105,6 +109,13 @@ ObjectStream::ObjectStream(XRef *xref, i
192 + // this is an arbitrary limit to avoid integer overflow problems
193 + // in the 'new Object[nObjects]' call (Acrobat apparently limits
194 + // object streams to 100-200 objects)
195 + if (nObjects > 1000000) {
196 + error(-1, "Too many objects in an object stream");
199 objs = new Object[nObjects];
200 objNums = (int *)gmallocn(nObjects, sizeof(int));
201 offsets = (int *)gmallocn(nObjects, sizeof(int));
202 @@ -161,10 +172,10 @@ ObjectStream::ObjectStream(XRef *xref, i
213 ObjectStream::~ObjectStream() {
214 @@ -837,6 +848,11 @@ Object *XRef::fetch(int num, int gen, Ob
217 objStr = new ObjectStream(this, e->offset);
218 + if (!objStr->isOk()) {
224 objStr->getObject(e->gen, num, obj);