aboutsummaryrefslogtreecommitdiff
path: root/editors/calligra/files/patch-post-1.3-koffice-CAN-2005-3193
blob: 69cb714d18af652b7c9ce0e87f16a2410ee6bea9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Index: filters/kword/pdf/xpdf/xpdf/Stream.cc
===================================================================
--- filters/kword/pdf/xpdf/xpdf/Stream.cc	(revision 485850)
+++ filters/kword/pdf/xpdf/xpdf/Stream.cc	(revision 486431)
@@ -404,18 +404,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() {
@@ -982,6 +997,10 @@ LZWStream::LZWStream(Stream *strA, int p
     FilterStream(strA) {
   if (predictor != 1) {
     pred = new StreamPredictor(this, predictor, columns, colors, bits);
+    if ( !pred->isOk()) {
+       delete pred;
+       pred = NULL;
+    }
   } else {
     pred = NULL;
   }
@@ -2861,6 +2880,10 @@ GBool DCTStream::readBaselineSOF() {
   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;
@@ -3179,6 +3202,10 @@ FlateStream::FlateStream(Stream *strA, i
     FilterStream(strA) {
   if (predictor != 1) {
     pred = new StreamPredictor(this, predictor, columns, colors, bits);
+    if ( !pred->isOk()) {
+        delete pred;
+        pred = NULL;
+    }
   } else {
     pred = NULL;
   }
Index: filters/kword/pdf/xpdf/xpdf/Stream.h
===================================================================
--- filters/kword/pdf/xpdf/xpdf/Stream.h	(revision 485850)
+++ filters/kword/pdf/xpdf/xpdf/Stream.h	(revision 486431)
@@ -227,6 +227,7 @@ public:
 
   int lookChar();
   int getChar();
+  GBool isOk() { return ok; }
 
 private:
 
@@ -242,6 +243,7 @@ private:
   int rowBytes;			// bytes per line
   Guchar *predLine;		// line buffer
   int predIdx;			// current index in predLine
+  GBool ok;
 };
 
 //------------------------------------------------------------------------