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 413-425
StreamPredictor::StreamPredictor(Stream
Link Here
|
413 |
width = widthA; |
414 |
width = widthA; |
414 |
nComps = nCompsA; |
415 |
nComps = nCompsA; |
415 |
nBits = nBitsA; |
416 |
nBits = nBitsA; |
|
|
417 |
predLine = NULL; |
418 |
ok = gFalse; |
419 |
|
420 |
if (width <= 0 || nComps <= 0 || nBits <= 0 || |
421 |
nComps >= INT_MAX / nBits || |
422 |
width >= INT_MAX / nComps / nBits) |
423 |
return; |
416 |
|
424 |
|
417 |
nVals = width * nComps; |
425 |
nVals = width * nComps; |
|
|
426 |
if (nVals * nBits + 7 <= 0) |
427 |
return; |
418 |
pixBytes = (nComps * nBits + 7) >> 3; |
428 |
pixBytes = (nComps * nBits + 7) >> 3; |
419 |
rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes; |
429 |
rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes; |
|
|
430 |
if (rowBytes < 0) |
431 |
return; |
432 |
|
420 |
predLine = (Guchar *)gmalloc(rowBytes); |
433 |
predLine = (Guchar *)gmalloc(rowBytes); |
421 |
memset(predLine, 0, rowBytes); |
434 |
memset(predLine, 0, rowBytes); |
422 |
predIdx = rowBytes; |
435 |
predIdx = rowBytes; |
|
|
436 |
|
437 |
ok = gTrue; |
423 |
} |
438 |
} |
424 |
|
439 |
|
425 |
StreamPredictor::~StreamPredictor() { |
440 |
StreamPredictor::~StreamPredictor() { |
Lines 1013-1018
LZWStream::LZWStream(Stream *strA, int p
Link Here
|
1013 |
FilterStream(strA) { |
1028 |
FilterStream(strA) { |
1014 |
if (predictor != 1) { |
1029 |
if (predictor != 1) { |
1015 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
1030 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
|
|
1031 |
if (!pred->isOk()) { |
1032 |
delete pred; |
1033 |
pred = NULL; |
1034 |
} |
1016 |
} else { |
1035 |
} else { |
1017 |
pred = NULL; |
1036 |
pred = NULL; |
1018 |
} |
1037 |
} |
Lines 1261-1266
CCITTFaxStream::CCITTFaxStream(Stream *s
Link Here
|
1261 |
endOfLine = endOfLineA; |
1280 |
endOfLine = endOfLineA; |
1262 |
byteAlign = byteAlignA; |
1281 |
byteAlign = byteAlignA; |
1263 |
columns = columnsA; |
1282 |
columns = columnsA; |
|
|
1283 |
if (columns < 1 || columns >= INT_MAX / sizeof(short)) { |
1284 |
error(-1, "invalid number of columns"); |
1285 |
exit(1); |
1286 |
} |
1264 |
rows = rowsA; |
1287 |
rows = rowsA; |
1265 |
endOfBlock = endOfBlockA; |
1288 |
endOfBlock = endOfBlockA; |
1266 |
black = blackA; |
1289 |
black = blackA; |
Lines 2899-2904
GBool DCTStream::readBaselineSOF() {
Link Here
|
2899 |
height = read16(); |
2922 |
height = read16(); |
2900 |
width = read16(); |
2923 |
width = read16(); |
2901 |
numComps = str->getChar(); |
2924 |
numComps = str->getChar(); |
|
|
2925 |
if (numComps <= 0 || numComps > 4) { |
2926 |
numComps = 0; |
2927 |
error(getPos(), "Bad number of components in DCT stream"); |
2928 |
return gFalse; |
2929 |
} |
2902 |
if (prec != 8) { |
2930 |
if (prec != 8) { |
2903 |
error(getPos(), "Bad DCT precision %d", prec); |
2931 |
error(getPos(), "Bad DCT precision %d", prec); |
2904 |
return gFalse; |
2932 |
return gFalse; |
Lines 2925-2930
GBool DCTStream::readProgressiveSOF() {
Link Here
|
2925 |
height = read16(); |
2953 |
height = read16(); |
2926 |
width = read16(); |
2954 |
width = read16(); |
2927 |
numComps = str->getChar(); |
2955 |
numComps = str->getChar(); |
|
|
2956 |
if (numComps <= 0 || numComps > 4) { |
2957 |
numComps = 0; |
2958 |
error(getPos(), "Bad number of components in DCT stream"); |
2959 |
return gFalse; |
2960 |
} |
2928 |
if (prec != 8) { |
2961 |
if (prec != 8) { |
2929 |
error(getPos(), "Bad DCT precision %d", prec); |
2962 |
error(getPos(), "Bad DCT precision %d", prec); |
2930 |
return gFalse; |
2963 |
return gFalse; |
Lines 2947-2952
GBool DCTStream::readScanInfo() {
Link Here
|
2947 |
|
2980 |
|
2948 |
length = read16() - 2; |
2981 |
length = read16() - 2; |
2949 |
scanInfo.numComps = str->getChar(); |
2982 |
scanInfo.numComps = str->getChar(); |
|
|
2983 |
if (scanInfo.numComps <= 0 || scanInfo.numComps > 4) { |
2984 |
scanInfo.numComps = 0; |
2985 |
error(getPos(), "Bad number of components in DCT stream"); |
2986 |
return gFalse; |
2987 |
} |
2950 |
--length; |
2988 |
--length; |
2951 |
if (length != 2 * scanInfo.numComps + 3) { |
2989 |
if (length != 2 * scanInfo.numComps + 3) { |
2952 |
error(getPos(), "Bad DCT scan info block"); |
2990 |
error(getPos(), "Bad DCT scan info block"); |
Lines 3021-3032
GBool DCTStream::readHuffmanTables() {
Link Here
|
3021 |
while (length > 0) { |
3059 |
while (length > 0) { |
3022 |
index = str->getChar(); |
3060 |
index = str->getChar(); |
3023 |
--length; |
3061 |
--length; |
3024 |
if ((index & 0x0f) >= 4) { |
3062 |
if ((index & ~0x10) >= 4 || (index & ~0x10) < 0) { |
3025 |
error(getPos(), "Bad DCT Huffman table"); |
3063 |
error(getPos(), "Bad DCT Huffman table"); |
3026 |
return gFalse; |
3064 |
return gFalse; |
3027 |
} |
3065 |
} |
3028 |
if (index & 0x10) { |
3066 |
if (index & 0x10) { |
3029 |
index &= 0x0f; |
3067 |
index &= 0x03; |
3030 |
if (index >= numACHuffTables) |
3068 |
if (index >= numACHuffTables) |
3031 |
numACHuffTables = index+1; |
3069 |
numACHuffTables = index+1; |
3032 |
tbl = &acHuffTables[index]; |
3070 |
tbl = &acHuffTables[index]; |
Lines 3144-3152
int DCTStream::readMarker() {
Link Here
|
3144 |
do { |
3182 |
do { |
3145 |
do { |
3183 |
do { |
3146 |
c = str->getChar(); |
3184 |
c = str->getChar(); |
|
|
3185 |
if(c == EOF) return EOF; |
3147 |
} while (c != 0xff); |
3186 |
} while (c != 0xff); |
3148 |
do { |
3187 |
do { |
3149 |
c = str->getChar(); |
3188 |
c = str->getChar(); |
|
|
3189 |
if(c == EOF) return EOF; |
3150 |
} while (c == 0xff); |
3190 |
} while (c == 0xff); |
3151 |
} while (c == 0x00); |
3191 |
} while (c == 0x00); |
3152 |
return c; |
3192 |
return c; |
Lines 3258-3263
FlateStream::FlateStream(Stream *strA, i
Link Here
|
3258 |
FilterStream(strA) { |
3298 |
FilterStream(strA) { |
3259 |
if (predictor != 1) { |
3299 |
if (predictor != 1) { |
3260 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
3300 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
|
|
3301 |
if (!pred->isOk()) { |
3302 |
delete pred; |
3303 |
pred = NULL; |
3304 |
} |
3261 |
} else { |
3305 |
} else { |
3262 |
pred = NULL; |
3306 |
pred = NULL; |
3263 |
} |
3307 |
} |