libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 6cc362072c05471bf45a1178d63ee394cc0c38e5
parent 1fb4237347796d78aef74f4d9ac89f216feeffc0
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 10 Mar 2006 23:35:00 +0000

0.5.10-diff

Diffstat:
Msrc/plugins/pdf/Stream.cc | 14++++++++++++--
Msrc/plugins/pdf/Stream.h | 2+-
Msrc/plugins/pdf/gmem.cc | 9+++++----
3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/plugins/pdf/Stream.cc b/src/plugins/pdf/Stream.cc @@ -16,6 +16,7 @@ #include <stdio.h> #include <stdlib.h> #include <stddef.h> +#include <limits.h> #ifndef WIN32 #include <unistd.h> #endif @@ -419,13 +420,14 @@ StreamPredictor::StreamPredictor(Stream *strA, int predictorA, nBits = nBitsA; predLine = NULL; ok = gFalse; + nVals = width * nComps; if (width <= 0 || nComps <= 0 || nBits <= 0 || nComps >= INT_MAX/nBits || - width >= INT_MAX/nComps/nBits) { + width >= INT_MAX/nComps/nBits || + nVals * nBits + 7 < 0) { return; } - nVals = width * nComps; if (nVals + 7 <= 0) { return; } @@ -1291,6 +1293,11 @@ CCITTFaxStream::CCITTFaxStream(Stream *strA, int encodingA, GBool endOfLineA, byteAlign = byteAlignA; columns = columnsA; + if (columns < 1) + columns = 1; + if (columns + 4 <= 0) + columns = INT_MAX - 4; + rows = rowsA; endOfBlock = endOfBlockA; black = blackA; @@ -2933,6 +2940,7 @@ GBool DCTStream::readBaselineSOF() { width = read16(); numComps = str->getChar(); if (numComps <= 0 || numComps > 4) { + numComps = 0; return gFalse; } @@ -2963,6 +2971,7 @@ GBool DCTStream::readProgressiveSOF() { width = read16(); numComps = str->getChar(); if (numComps <= 0 || numComps > 4) { + numComps = 0; return gFalse; } if (prec != 8) { @@ -3076,6 +3085,7 @@ GBool DCTStream::readHuffmanTables() { numACHuffTables = index+1; tbl = &acHuffTables[index]; } else { + index &= 0x0f; if (index >= numDCHuffTables) numDCHuffTables = index+1; tbl = &dcHuffTables[index]; diff --git a/src/plugins/pdf/Stream.h b/src/plugins/pdf/Stream.h @@ -534,7 +534,7 @@ private: short getWhiteCode(); short getBlackCode(); short lookBits(int n); - void eatBits(int n) { inputBits -= n; } + void eatBits(int n) { if ((inputBits -= n) < 0) inputBits = 0; } }; //------------------------------------------------------------------------ diff --git a/src/plugins/pdf/gmem.cc b/src/plugins/pdf/gmem.cc @@ -10,6 +10,7 @@ #include <stdlib.h> #include <stddef.h> #include <string.h> +#include <limits.h> #include "gmem.h" #ifdef DEBUG_MEM @@ -61,7 +62,7 @@ void *gmalloc(int size) { int lst; unsigned long *trl, *p; - if (size == 0) + if (size <= 0) return NULL; size1 = gMemDataSize(size); if (!(mem = (char *)malloc(size1 + gMemHdrSize + gMemTrlSize))) { @@ -83,7 +84,7 @@ void *gmalloc(int size) { #else void *p; - if (size == 0) + if (size <= 0) return NULL; if (!(p = malloc(size))) { fprintf(stderr, "Out of memory\n"); @@ -99,7 +100,7 @@ void *grealloc(void *p, int size) { void *q; int oldSize; - if (size == 0) { + if (size <= 0) { if (p) gfree(p); return NULL; @@ -117,7 +118,7 @@ void *grealloc(void *p, int size) { #else void *q; - if (size == 0) { + if (size <= 0) { if (p) free(p); return NULL;