|
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; |
| 412 |
|
415 |
|
|
|
416 |
if (width <= 0 || nComps <= 0 || nBits <= 0 || |
| 417 |
nComps >= INT_MAX/nBits || |
| 418 |
width >= INT_MAX/nComps/nBits) { |
| 419 |
return; |
| 420 |
} |
| 413 |
nVals = width * nComps; |
421 |
nVals = width * nComps; |
|
|
422 |
if (nVals * nBits + 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 981-986
LZWStream::LZWStream(Stream *strA, int p
Link Here
|
| 981 |
FilterStream(strA) { |
997 |
FilterStream(strA) { |
| 982 |
if (predictor != 1) { |
998 |
if (predictor != 1) { |
| 983 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
999 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
|
|
1000 |
if (!pred->isOk()) { |
| 1001 |
delete pred; |
| 1002 |
pred = NULL; |
| 1003 |
} |
| 984 |
} else { |
1004 |
} else { |
| 985 |
pred = NULL; |
1005 |
pred = NULL; |
| 986 |
} |
1006 |
} |
|
Lines 1226-1231
CCITTFaxStream::CCITTFaxStream(Stream *s
Link Here
|
| 1226 |
endOfLine = endOfLineA; |
1246 |
endOfLine = endOfLineA; |
| 1227 |
byteAlign = byteAlignA; |
1247 |
byteAlign = byteAlignA; |
| 1228 |
columns = columnsA; |
1248 |
columns = columnsA; |
|
|
1249 |
if (columns < 1 || columns >= INT_MAX / sizeof(short)) { |
| 1250 |
error(-1, "invalid number of columns"); |
| 1251 |
exit(1); |
| 1252 |
} |
| 1229 |
rows = rowsA; |
1253 |
rows = rowsA; |
| 1230 |
endOfBlock = endOfBlockA; |
1254 |
endOfBlock = endOfBlockA; |
| 1231 |
black = blackA; |
1255 |
black = blackA; |
|
Lines 2864-2869
GBool DCTStream::readBaselineSOF() {
Link Here
|
| 2864 |
height = read16(); |
2888 |
height = read16(); |
| 2865 |
width = read16(); |
2889 |
width = read16(); |
| 2866 |
numComps = str->getChar(); |
2890 |
numComps = str->getChar(); |
|
|
2891 |
if (numComps <= 0 || numComps > 4) { |
| 2892 |
numComps = 0; |
| 2893 |
error(getPos(), "Bad number of components in DCT stream"); |
| 2894 |
return gFalse; |
| 2895 |
} |
| 2867 |
if (prec != 8) { |
2896 |
if (prec != 8) { |
| 2868 |
error(getPos(), "Bad DCT precision %d", prec); |
2897 |
error(getPos(), "Bad DCT precision %d", prec); |
| 2869 |
return gFalse; |
2898 |
return gFalse; |
|
Lines 2890-2895
GBool DCTStream::readProgressiveSOF() {
Link Here
|
| 2890 |
height = read16(); |
2919 |
height = read16(); |
| 2891 |
width = read16(); |
2920 |
width = read16(); |
| 2892 |
numComps = str->getChar(); |
2921 |
numComps = str->getChar(); |
|
|
2922 |
if (numComps <= 0 || numComps > 4) { |
| 2923 |
numComps = 0; |
| 2924 |
error(getPos(), "Bad number of components in DCT stream"); |
| 2925 |
return gFalse; |
| 2926 |
} |
| 2893 |
if (prec != 8) { |
2927 |
if (prec != 8) { |
| 2894 |
error(getPos(), "Bad DCT precision %d", prec); |
2928 |
error(getPos(), "Bad DCT precision %d", prec); |
| 2895 |
return gFalse; |
2929 |
return gFalse; |
|
Lines 2912-2917
GBool DCTStream::readScanInfo() {
Link Here
|
| 2912 |
|
2946 |
|
| 2913 |
length = read16() - 2; |
2947 |
length = read16() - 2; |
| 2914 |
scanInfo.numComps = str->getChar(); |
2948 |
scanInfo.numComps = str->getChar(); |
|
|
2949 |
if (scanInfo.numComps <= 0 || scanInfo.numComps > 4) { |
| 2950 |
error(getPos(), "Bad number of components in DCT stream"); |
| 2951 |
return gFalse; |
| 2952 |
} |
| 2915 |
--length; |
2953 |
--length; |
| 2916 |
if (length != 2 * scanInfo.numComps + 3) { |
2954 |
if (length != 2 * scanInfo.numComps + 3) { |
| 2917 |
error(getPos(), "Bad DCT scan info block"); |
2955 |
error(getPos(), "Bad DCT scan info block"); |
|
Lines 2979-2990
GBool DCTStream::readHuffmanTables() {
Link Here
|
| 2979 |
while (length > 0) { |
3017 |
while (length > 0) { |
| 2980 |
index = str->getChar(); |
3018 |
index = str->getChar(); |
| 2981 |
--length; |
3019 |
--length; |
| 2982 |
if ((index & 0x0f) >= 4) { |
3020 |
if ((index & ~0x10) >= 4 || (index & ~0x10) < 0) { |
| 2983 |
error(getPos(), "Bad DCT Huffman table"); |
3021 |
error(getPos(), "Bad DCT Huffman table"); |
| 2984 |
return gFalse; |
3022 |
return gFalse; |
| 2985 |
} |
3023 |
} |
| 2986 |
if (index & 0x10) { |
3024 |
if (index & 0x10) { |
| 2987 |
index &= 0x0f; |
3025 |
index &= 0x03; |
| 2988 |
if (index >= numACHuffTables) |
3026 |
if (index >= numACHuffTables) |
| 2989 |
numACHuffTables = index+1; |
3027 |
numACHuffTables = index+1; |
| 2990 |
tbl = &acHuffTables[index]; |
3028 |
tbl = &acHuffTables[index]; |
|
Lines 3072-3080
int DCTStream::readMarker() {
Link Here
|
| 3072 |
do { |
3110 |
do { |
| 3073 |
do { |
3111 |
do { |
| 3074 |
c = str->getChar(); |
3112 |
c = str->getChar(); |
|
|
3113 |
if(c == EOF) return EOF; |
| 3075 |
} while (c != 0xff); |
3114 |
} while (c != 0xff); |
| 3076 |
do { |
3115 |
do { |
| 3077 |
c = str->getChar(); |
3116 |
c = str->getChar(); |
|
|
3117 |
if(c == EOF) return EOF; |
| 3078 |
} while (c == 0xff); |
3118 |
} while (c == 0xff); |
| 3079 |
} while (c == 0x00); |
3119 |
} while (c == 0x00); |
| 3080 |
return c; |
3120 |
return c; |
|
Lines 3182-3187
FlateStream::FlateStream(Stream *strA, i
Link Here
|
| 3182 |
FilterStream(strA) { |
3222 |
FilterStream(strA) { |
| 3183 |
if (predictor != 1) { |
3223 |
if (predictor != 1) { |
| 3184 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
3224 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
|
|
3225 |
if (!pred->isOk()) { |
| 3226 |
delete pred; |
| 3227 |
pred = NULL; |
| 3228 |
} |
| 3185 |
} else { |
3229 |
} else { |
| 3186 |
pred = NULL; |
3230 |
pred = NULL; |
| 3187 |
} |
3231 |
} |