Lines 15-20
Link Here
|
15 |
#include <stdio.h> |
15 |
#include <stdio.h> |
16 |
#include <stdlib.h> |
16 |
#include <stdlib.h> |
17 |
#include <stddef.h> |
17 |
#include <stddef.h> |
|
|
18 |
#include <limits.h> |
18 |
#ifndef WIN32 |
19 |
#ifndef WIN32 |
19 |
#include <unistd.h> |
20 |
#include <unistd.h> |
20 |
#endif |
21 |
#endif |
Lines 409-421
StreamPredictor::StreamPredictor(Stream
Link Here
|
409 |
width = widthA; |
410 |
width = widthA; |
410 |
nComps = nCompsA; |
411 |
nComps = nCompsA; |
411 |
nBits = nBitsA; |
412 |
nBits = nBitsA; |
|
|
413 |
predLine = NULL; |
414 |
ok = gFalse; |
415 |
|
416 |
if (width <= 0 || nComps <= 0 || nBits <= 0 || |
417 |
nComps >= INT_MAX / nBits || |
418 |
width >= INT_MAX / nComps / nBits) |
419 |
return; |
412 |
|
420 |
|
413 |
nVals = width * nComps; |
421 |
nVals = width * nComps; |
|
|
422 |
if (nVals + 7 <= 0) |
423 |
return; |
424 |
|
414 |
pixBytes = (nComps * nBits + 7) >> 3; |
425 |
pixBytes = (nComps * nBits + 7) >> 3; |
415 |
rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes; |
426 |
rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes; |
|
|
427 |
if (rowBytes < 0) |
428 |
return; |
429 |
|
416 |
predLine = (Guchar *)gmalloc(rowBytes); |
430 |
predLine = (Guchar *)gmalloc(rowBytes); |
417 |
memset(predLine, 0, rowBytes); |
431 |
memset(predLine, 0, rowBytes); |
418 |
predIdx = rowBytes; |
432 |
predIdx = rowBytes; |
|
|
433 |
|
434 |
ok = gTrue; |
419 |
} |
435 |
} |
420 |
|
436 |
|
421 |
StreamPredictor::~StreamPredictor() { |
437 |
StreamPredictor::~StreamPredictor() { |
Lines 982-987
LZWStream::LZWStream(Stream *strA, int p
Link Here
|
982 |
FilterStream(strA) { |
998 |
FilterStream(strA) { |
983 |
if (predictor != 1) { |
999 |
if (predictor != 1) { |
984 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
1000 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
|
|
1001 |
if ( !pred->isOk()) { |
1002 |
delete pred; |
1003 |
pred = NULL; |
1004 |
} |
985 |
} else { |
1005 |
} else { |
986 |
pred = NULL; |
1006 |
pred = NULL; |
987 |
} |
1007 |
} |
Lines 1227-1232
CCITTFaxStream::CCITTFaxStream(Stream *s
Link Here
|
1227 |
endOfLine = endOfLineA; |
1247 |
endOfLine = endOfLineA; |
1228 |
byteAlign = byteAlignA; |
1248 |
byteAlign = byteAlignA; |
1229 |
columns = columnsA; |
1249 |
columns = columnsA; |
|
|
1250 |
if (columns < 1 || columns + 2 < 0 || columns + 3 < 0 || |
1251 |
(columns + 2) >= INT_MAX / sizeof(short) || (columns + 3) >= INT_MAX / sizeof(short)) { |
1252 |
error(-1, "invalid number of columns"); |
1253 |
exit(1); |
1254 |
} |
1230 |
rows = rowsA; |
1255 |
rows = rowsA; |
1231 |
endOfBlock = endOfBlockA; |
1256 |
endOfBlock = endOfBlockA; |
1232 |
black = blackA; |
1257 |
black = blackA; |
Lines 2861-2866
GBool DCTStream::readBaselineSOF() {
Link Here
|
2861 |
height = read16(); |
2886 |
height = read16(); |
2862 |
width = read16(); |
2887 |
width = read16(); |
2863 |
numComps = str->getChar(); |
2888 |
numComps = str->getChar(); |
|
|
2889 |
if (numComps <= 0 || numComps > 4) { |
2890 |
numComps = 0; |
2891 |
error(getPos(), "Bad number of components in DCT stream"); |
2892 |
return gFalse; |
2893 |
} |
2864 |
if (prec != 8) { |
2894 |
if (prec != 8) { |
2865 |
error(getPos(), "Bad DCT precision %d", prec); |
2895 |
error(getPos(), "Bad DCT precision %d", prec); |
2866 |
return gFalse; |
2896 |
return gFalse; |
Lines 2887-2892
GBool DCTStream::readProgressiveSOF() {
Link Here
|
2887 |
height = read16(); |
2917 |
height = read16(); |
2888 |
width = read16(); |
2918 |
width = read16(); |
2889 |
numComps = str->getChar(); |
2919 |
numComps = str->getChar(); |
|
|
2920 |
if (numComps <= 0 || numComps > 4) { |
2921 |
numComps = 0; |
2922 |
error(getPos(), "Bad number of components in DCT stream"); |
2923 |
return gFalse; |
2924 |
} |
2890 |
if (prec != 8) { |
2925 |
if (prec != 8) { |
2891 |
error(getPos(), "Bad DCT precision %d", prec); |
2926 |
error(getPos(), "Bad DCT precision %d", prec); |
2892 |
return gFalse; |
2927 |
return gFalse; |
Lines 2909-2914
GBool DCTStream::readScanInfo() {
Link Here
|
2909 |
|
2944 |
|
2910 |
length = read16() - 2; |
2945 |
length = read16() - 2; |
2911 |
scanInfo.numComps = str->getChar(); |
2946 |
scanInfo.numComps = str->getChar(); |
|
|
2947 |
if (scanInfo.numComps <= 0 || scanInfo.numComps > 4) { |
2948 |
scanInfo.numComps = 0; |
2949 |
error(getPos(), "Bad number of components in DCT stream"); |
2950 |
return gFalse; |
2951 |
} |
2912 |
--length; |
2952 |
--length; |
2913 |
if (length != 2 * scanInfo.numComps + 3) { |
2953 |
if (length != 2 * scanInfo.numComps + 3) { |
2914 |
error(getPos(), "Bad DCT scan info block"); |
2954 |
error(getPos(), "Bad DCT scan info block"); |
Lines 2976-2987
GBool DCTStream::readHuffmanTables() {
Link Here
|
2976 |
while (length > 0) { |
3016 |
while (length > 0) { |
2977 |
index = str->getChar(); |
3017 |
index = str->getChar(); |
2978 |
--length; |
3018 |
--length; |
2979 |
if ((index & 0x0f) >= 4) { |
3019 |
if ((index & ~0x10) >= 4 || (index & ~0x10) < 0) { |
2980 |
error(getPos(), "Bad DCT Huffman table"); |
3020 |
error(getPos(), "Bad DCT Huffman table"); |
2981 |
return gFalse; |
3021 |
return gFalse; |
2982 |
} |
3022 |
} |
2983 |
if (index & 0x10) { |
3023 |
if (index & 0x10) { |
2984 |
index &= 0x0f; |
3024 |
index &= 0x03; |
2985 |
if (index >= numACHuffTables) |
3025 |
if (index >= numACHuffTables) |
2986 |
numACHuffTables = index+1; |
3026 |
numACHuffTables = index+1; |
2987 |
tbl = &acHuffTables[index]; |
3027 |
tbl = &acHuffTables[index]; |
Lines 3069-3077
int DCTStream::readMarker() {
Link Here
|
3069 |
do { |
3109 |
do { |
3070 |
do { |
3110 |
do { |
3071 |
c = str->getChar(); |
3111 |
c = str->getChar(); |
|
|
3112 |
if(c == EOF) return EOF; |
3072 |
} while (c != 0xff); |
3113 |
} while (c != 0xff); |
3073 |
do { |
3114 |
do { |
3074 |
c = str->getChar(); |
3115 |
c = str->getChar(); |
|
|
3116 |
if(c == EOF) return EOF; |
3075 |
} while (c == 0xff); |
3117 |
} while (c == 0xff); |
3076 |
} while (c == 0x00); |
3118 |
} while (c == 0x00); |
3077 |
return c; |
3119 |
return c; |
Lines 3179-3184
FlateStream::FlateStream(Stream *strA, i
Link Here
|
3179 |
FilterStream(strA) { |
3221 |
FilterStream(strA) { |
3180 |
if (predictor != 1) { |
3222 |
if (predictor != 1) { |
3181 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
3223 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
|
|
3224 |
if ( !pred->isOk()) { |
3225 |
delete pred; |
3226 |
pred = NULL; |
3227 |
} |
3182 |
} else { |
3228 |
} else { |
3183 |
pred = NULL; |
3229 |
pred = NULL; |
3184 |
} |
3230 |
} |