mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
8.4 KiB

  1. Index: kpdf/xpdf/xpdf/JBIG2Stream.cc
  2. ===================================================================
  3. --- ./kpdf/xpdf/xpdf/JBIG2Stream.cc (revision 481099)
  4. +++ ./kpdf/xpdf/xpdf/JBIG2Stream.cc (revision 488715)
  5. @@ -7,6 +7,7 @@
  6. //========================================================================
  7. #include <aconf.h>
  8. +#include <limits.h>
  9. #ifdef USE_GCC_PRAGMAS
  10. #pragma implementation
  11. @@ -681,6 +682,12 @@ JBIG2Bitmap::JBIG2Bitmap(Guint segNumA,
  12. w = wA;
  13. h = hA;
  14. line = (wA + 7) >> 3;
  15. +
  16. + if (h < 0 || line <= 0 || h >= (INT_MAX - 1) / line ) {
  17. + data = NULL;
  18. + return;
  19. + }
  20. +
  21. // need to allocate one extra guard byte for use in combine()
  22. data = (Guchar *)gmalloc(h * line + 1);
  23. data[h * line] = 0;
  24. @@ -692,6 +699,12 @@ JBIG2Bitmap::JBIG2Bitmap(Guint segNumA,
  25. w = bitmap->w;
  26. h = bitmap->h;
  27. line = bitmap->line;
  28. +
  29. + if (h < 0 || line <= 0 || h >= (INT_MAX - 1) / line) {
  30. + data = NULL;
  31. + return;
  32. + }
  33. +
  34. // need to allocate one extra guard byte for use in combine()
  35. data = (Guchar *)gmalloc(h * line + 1);
  36. memcpy(data, bitmap->data, h * line);
  37. @@ -720,7 +733,8 @@ JBIG2Bitmap *JBIG2Bitmap::getSlice(Guint
  38. }
  39. void JBIG2Bitmap::expand(int newH, Guint pixel) {
  40. - if (newH <= h) {
  41. +
  42. + if (newH <= h || line <= 0 || newH >= (INT_MAX - 1) / line) {
  43. return;
  44. }
  45. // need to allocate one extra guard byte for use in combine()
  46. @@ -2305,6 +2319,15 @@ void JBIG2Stream::readHalftoneRegionSeg(
  47. error(getPos(), "Bad symbol dictionary reference in JBIG2 halftone segment");
  48. return;
  49. }
  50. + if (gridH == 0 || gridW >= INT_MAX / gridH) {
  51. + error(getPos(), "Bad size in JBIG2 halftone segment");
  52. + return;
  53. + }
  54. + if (h < 0 || w == 0 || h >= INT_MAX / w) {
  55. + error(getPos(), "Bad size in JBIG2 bitmap segment");
  56. + return;
  57. + }
  58. +
  59. patternDict = (JBIG2PatternDict *)seg;
  60. bpp = 0;
  61. i = 1;
  62. @@ -2936,6 +2959,9 @@ JBIG2Bitmap *JBIG2Stream::readGenericRef
  63. JBIG2BitmapPtr tpgrCXPtr0, tpgrCXPtr1, tpgrCXPtr2;
  64. int x, y, pix;
  65. + if (w < 0 || h <= 0 || w >= INT_MAX / h)
  66. + return NULL;
  67. +
  68. bitmap = new JBIG2Bitmap(0, w, h);
  69. bitmap->clearToZero();
  70. Index: kpdf/xpdf/xpdf/Stream.cc
  71. ===================================================================
  72. --- ./kpdf/xpdf/xpdf/Stream.cc (revision 481099)
  73. +++ ./kpdf/xpdf/xpdf/Stream.cc (revision 488715)
  74. @@ -15,6 +15,7 @@
  75. #include <stdio.h>
  76. #include <stdlib.h>
  77. #include <stddef.h>
  78. +#include <limits.h>
  79. #ifndef WIN32
  80. #include <unistd.h>
  81. #endif
  82. @@ -408,13 +409,27 @@ StreamPredictor::StreamPredictor(Stream
  83. width = widthA;
  84. nComps = nCompsA;
  85. nBits = nBitsA;
  86. + predLine = NULL;
  87. + ok = gFalse;
  88. +
  89. + if (width <= 0 || nComps <= 0 || nBits <= 0 ||
  90. + nComps >= INT_MAX / nBits ||
  91. + width >= INT_MAX / nComps / nBits)
  92. + return;
  93. nVals = width * nComps;
  94. + if (nVals * nBits + 7 <= 0)
  95. + return;
  96. pixBytes = (nComps * nBits + 7) >> 3;
  97. rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes;
  98. + if (rowBytes < 0)
  99. + return;
  100. +
  101. predLine = (Guchar *)gmalloc(rowBytes);
  102. memset(predLine, 0, rowBytes);
  103. predIdx = rowBytes;
  104. +
  105. + ok = gTrue;
  106. }
  107. StreamPredictor::~StreamPredictor() {
  108. @@ -1006,6 +1021,10 @@ LZWStream::LZWStream(Stream *strA, int p
  109. FilterStream(strA) {
  110. if (predictor != 1) {
  111. pred = new StreamPredictor(this, predictor, columns, colors, bits);
  112. + if (!pred->isOk()) {
  113. + delete pred;
  114. + pred = NULL;
  115. + }
  116. } else {
  117. pred = NULL;
  118. }
  119. @@ -1258,8 +1277,9 @@ CCITTFaxStream::CCITTFaxStream(Stream *s
  120. endOfLine = endOfLineA;
  121. byteAlign = byteAlignA;
  122. columns = columnsA;
  123. - if (columns < 1) {
  124. - columns = 1;
  125. + if (columns < 1 || columns >= INT_MAX / sizeof(short)) {
  126. + error(getPos(), "Bad number of columns in CCITTFaxStream");
  127. + exit(1);
  128. }
  129. rows = rowsA;
  130. endOfBlock = endOfBlockA;
  131. @@ -2903,7 +2923,12 @@ GBool DCTStream::readBaselineSOF() {
  132. height = read16();
  133. width = read16();
  134. numComps = str->getChar();
  135. - if (prec != 8) {
  136. + if (numComps <= 0 || numComps > 4) {
  137. + numComps = 0;
  138. + error(getPos(), "Bad number of components in DCT stream", prec);
  139. + return gFalse;
  140. + }
  141. + if (prec != 8) {
  142. error(getPos(), "Bad DCT precision %d", prec);
  143. return gFalse;
  144. }
  145. @@ -2929,6 +2954,11 @@ GBool DCTStream::readProgressiveSOF() {
  146. height = read16();
  147. width = read16();
  148. numComps = str->getChar();
  149. + if (numComps <= 0 || numComps > 4) {
  150. + numComps = 0;
  151. + error(getPos(), "Bad number of components in DCT stream");
  152. + return gFalse;
  153. + }
  154. if (prec != 8) {
  155. error(getPos(), "Bad DCT precision %d", prec);
  156. return gFalse;
  157. @@ -2951,6 +2981,11 @@ GBool DCTStream::readScanInfo() {
  158. length = read16() - 2;
  159. scanInfo.numComps = str->getChar();
  160. + if (scanInfo.numComps <= 0 || scanInfo.numComps > 4) {
  161. + scanInfo.numComps = 0;
  162. + error(getPos(), "Bad number of components in DCT stream");
  163. + return gFalse;
  164. + }
  165. --length;
  166. if (length != 2 * scanInfo.numComps + 3) {
  167. error(getPos(), "Bad DCT scan info block");
  168. @@ -3035,12 +3070,12 @@ GBool DCTStream::readHuffmanTables() {
  169. while (length > 0) {
  170. index = str->getChar();
  171. --length;
  172. - if ((index & 0x0f) >= 4) {
  173. + if ((index & ~0x10) >= 4 || (index & ~0x10) < 0) {
  174. error(getPos(), "Bad DCT Huffman table");
  175. return gFalse;
  176. }
  177. if (index & 0x10) {
  178. - index &= 0x0f;
  179. + index &= 0x03;
  180. if (index >= numACHuffTables)
  181. numACHuffTables = index+1;
  182. tbl = &acHuffTables[index];
  183. @@ -3833,6 +3868,10 @@ FlateStream::FlateStream(Stream *strA, i
  184. FilterStream(strA) {
  185. if (predictor != 1) {
  186. pred = new StreamPredictor(this, predictor, columns, colors, bits);
  187. + if (!pred->isOk()) {
  188. + delete pred;
  189. + pred = NULL;
  190. + }
  191. } else {
  192. pred = NULL;
  193. }
  194. Index: kpdf/xpdf/xpdf/Stream.h
  195. ===================================================================
  196. --- ./kpdf/xpdf/xpdf/Stream.h (revision 481099)
  197. +++ ./kpdf/xpdf/xpdf/Stream.h (revision 488715)
  198. @@ -232,6 +232,8 @@ public:
  199. ~StreamPredictor();
  200. + GBool isOk() { return ok; }
  201. +
  202. int lookChar();
  203. int getChar();
  204. @@ -249,6 +251,7 @@ private:
  205. int rowBytes; // bytes per line
  206. Guchar *predLine; // line buffer
  207. int predIdx; // current index in predLine
  208. + GBool ok;
  209. };
  210. //------------------------------------------------------------------------
  211. --- ./kpdf/xpdf/xpdf/JPXStream.cc (revision 481099)
  212. +++ ./kpdf/xpdf/xpdf/JPXStream.cc (revision 488715)
  213. @@ -7,6 +7,7 @@
  214. //========================================================================
  215. #include <aconf.h>
  216. +#include <limits.h>
  217. #ifdef USE_GCC_PRAGMAS
  218. #pragma implementation
  219. @@ -783,7 +784,7 @@ GBool JPXStream::readCodestream(Guint /*
  220. int segType;
  221. GBool haveSIZ, haveCOD, haveQCD, haveSOT;
  222. Guint precinctSize, style;
  223. - Guint segLen, capabilities, comp, i, j, r;
  224. + Guint segLen, capabilities, nTiles, comp, i, j, r;
  225. //----- main header
  226. haveSIZ = haveCOD = haveQCD = haveSOT = gFalse;
  227. @@ -818,8 +819,13 @@ GBool JPXStream::readCodestream(Guint /*
  228. / img.xTileSize;
  229. img.nYTiles = (img.ySize - img.yTileOffset + img.yTileSize - 1)
  230. / img.yTileSize;
  231. - img.tiles = (JPXTile *)gmallocn(img.nXTiles * img.nYTiles,
  232. - sizeof(JPXTile));
  233. + nTiles = img.nXTiles * img.nYTiles;
  234. + // check for overflow before allocating memory
  235. + if (img.nXTiles <= 0 || img.nYTiles <= 0 || img.nXTiles >= INT_MAX / img.nYTiles) {
  236. + error(getPos(), "Bad tile count in JPX SIZ marker segment");
  237. + return gFalse;
  238. + }
  239. + img.tiles = (JPXTile *)gmallocn(nTiles, sizeof(JPXTile));
  240. for (i = 0; i < img.nXTiles * img.nYTiles; ++i) {
  241. img.tiles[i].tileComps = (JPXTileComp *)gmallocn(img.nComps,
  242. sizeof(JPXTileComp));
  243. Index: kpdf/xpdf/goo/gmem.c
  244. ===================================================================
  245. --- ./kpdf/xpdf/goo/gmem.c (revision 481099)
  246. +++ ./kpdf/xpdf/goo/gmem.c (revision 488715)
  247. @@ -11,6 +11,7 @@
  248. #include <stdlib.h>
  249. #include <stddef.h>
  250. #include <string.h>
  251. +#include <limits.h>
  252. #include "gmem.h"
  253. #ifdef DEBUG_MEM
  254. @@ -141,7 +142,7 @@ void *gmallocn(int nObjs, int objSize) {
  255. int n;
  256. n = nObjs * objSize;
  257. - if (objSize == 0 || n / objSize != nObjs) {
  258. + if (objSize <= 0 || nObjs < 0 || nObjs >= INT_MAX / objSize) {
  259. fprintf(stderr, "Bogus memory allocation size\n");
  260. exit(1);
  261. }
  262. @@ -152,7 +153,7 @@ void *greallocn(void *p, int nObjs, int
  263. int n;
  264. n = nObjs * objSize;
  265. - if (objSize == 0 || n / objSize != nObjs) {
  266. + if (objSize <= 0 || nObjs < 0 || nObjs >= INT_MAX / objSize) {
  267. fprintf(stderr, "Bogus memory allocation size\n");
  268. exit(1);
  269. }