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