|
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 408-420
StreamPredictor::StreamPredictor(Stream
Link Here
|
| 408 |
width = widthA; |
409 |
width = widthA; |
| 409 |
nComps = nCompsA; |
410 |
nComps = nCompsA; |
| 410 |
nBits = nBitsA; |
411 |
nBits = nBitsA; |
|
|
412 |
predLine = NULL; |
| 413 |
ok = gFalse; |
| 414 |
|
| 415 |
if (width <= 0 || nComps <= 0 || nBits <= 0 || |
| 416 |
nComps >= INT_MAX / nBits || |
| 417 |
width >= INT_MAX / nComps / nBits) |
| 418 |
return; |
| 411 |
|
419 |
|
| 412 |
nVals = width * nComps; |
420 |
nVals = width * nComps; |
|
|
421 |
if (nVals * nBits + 7 <= 0) |
| 422 |
return; |
| 413 |
pixBytes = (nComps * nBits + 7) >> 3; |
423 |
pixBytes = (nComps * nBits + 7) >> 3; |
| 414 |
rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes; |
424 |
rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes; |
|
|
425 |
if (rowBytes < 0) |
| 426 |
return; |
| 427 |
|
| 415 |
predLine = (Guchar *)gmalloc(rowBytes); |
428 |
predLine = (Guchar *)gmalloc(rowBytes); |
| 416 |
memset(predLine, 0, rowBytes); |
429 |
memset(predLine, 0, rowBytes); |
| 417 |
predIdx = rowBytes; |
430 |
predIdx = rowBytes; |
|
|
431 |
|
| 432 |
ok = gTrue; |
| 418 |
} |
433 |
} |
| 419 |
|
434 |
|
| 420 |
StreamPredictor::~StreamPredictor() { |
435 |
StreamPredictor::~StreamPredictor() { |
|
Lines 1006-1011
LZWStream::LZWStream(Stream *strA, int p
Link Here
|
| 1006 |
FilterStream(strA) { |
1021 |
FilterStream(strA) { |
| 1007 |
if (predictor != 1) { |
1022 |
if (predictor != 1) { |
| 1008 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
1023 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
|
|
1024 |
if (!pred->isOk()) { |
| 1025 |
delete pred; |
| 1026 |
pred = NULL; |
| 1027 |
} |
| 1009 |
} else { |
1028 |
} else { |
| 1010 |
pred = NULL; |
1029 |
pred = NULL; |
| 1011 |
} |
1030 |
} |
|
Lines 1258-1265
CCITTFaxStream::CCITTFaxStream(Stream *s
Link Here
|
| 1258 |
endOfLine = endOfLineA; |
1277 |
endOfLine = endOfLineA; |
| 1259 |
byteAlign = byteAlignA; |
1278 |
byteAlign = byteAlignA; |
| 1260 |
columns = columnsA; |
1279 |
columns = columnsA; |
| 1261 |
if (columns < 1) { |
1280 |
if (columns < 1 || columns >= INT_MAX / sizeof(short)) { |
| 1262 |
columns = 1; |
1281 |
error(getPos(), "Bad number of columns in CCITTFaxStream"); |
|
|
1282 |
exit(1); |
| 1263 |
} |
1283 |
} |
| 1264 |
rows = rowsA; |
1284 |
rows = rowsA; |
| 1265 |
endOfBlock = endOfBlockA; |
1285 |
endOfBlock = endOfBlockA; |
|
Lines 2903-2909
GBool DCTStream::readBaselineSOF() {
Link Here
|
| 2903 |
height = read16(); |
2923 |
height = read16(); |
| 2904 |
width = read16(); |
2924 |
width = read16(); |
| 2905 |
numComps = str->getChar(); |
2925 |
numComps = str->getChar(); |
| 2906 |
if (prec != 8) { |
2926 |
if (numComps <= 0 || numComps > 4) { |
|
|
2927 |
numComps = 0; |
| 2928 |
error(getPos(), "Bad number of components in DCT stream", prec); |
| 2929 |
return gFalse; |
| 2930 |
} |
| 2931 |
if (prec != 8) { |
| 2907 |
error(getPos(), "Bad DCT precision %d", prec); |
2932 |
error(getPos(), "Bad DCT precision %d", prec); |
| 2908 |
return gFalse; |
2933 |
return gFalse; |
| 2909 |
} |
2934 |
} |
|
Lines 2929-2934
GBool DCTStream::readProgressiveSOF() {
Link Here
|
| 2929 |
height = read16(); |
2954 |
height = read16(); |
| 2930 |
width = read16(); |
2955 |
width = read16(); |
| 2931 |
numComps = str->getChar(); |
2956 |
numComps = str->getChar(); |
|
|
2957 |
if (numComps <= 0 || numComps > 4) { |
| 2958 |
numComps = 0; |
| 2959 |
error(getPos(), "Bad number of components in DCT stream"); |
| 2960 |
return gFalse; |
| 2961 |
} |
| 2932 |
if (prec != 8) { |
2962 |
if (prec != 8) { |
| 2933 |
error(getPos(), "Bad DCT precision %d", prec); |
2963 |
error(getPos(), "Bad DCT precision %d", prec); |
| 2934 |
return gFalse; |
2964 |
return gFalse; |
|
Lines 2951-2956
GBool DCTStream::readScanInfo() {
Link Here
|
| 2951 |
|
2981 |
|
| 2952 |
length = read16() - 2; |
2982 |
length = read16() - 2; |
| 2953 |
scanInfo.numComps = str->getChar(); |
2983 |
scanInfo.numComps = str->getChar(); |
|
|
2984 |
if (scanInfo.numComps <= 0 || scanInfo.numComps > 4) { |
| 2985 |
scanInfo.numComps = 0; |
| 2986 |
error(getPos(), "Bad number of components in DCT stream"); |
| 2987 |
return gFalse; |
| 2988 |
} |
| 2954 |
--length; |
2989 |
--length; |
| 2955 |
if (length != 2 * scanInfo.numComps + 3) { |
2990 |
if (length != 2 * scanInfo.numComps + 3) { |
| 2956 |
error(getPos(), "Bad DCT scan info block"); |
2991 |
error(getPos(), "Bad DCT scan info block"); |
|
Lines 3035-3046
GBool DCTStream::readHuffmanTables() {
Link Here
|
| 3035 |
while (length > 0) { |
3070 |
while (length > 0) { |
| 3036 |
index = str->getChar(); |
3071 |
index = str->getChar(); |
| 3037 |
--length; |
3072 |
--length; |
| 3038 |
if ((index & 0x0f) >= 4) { |
3073 |
if ((index & ~0x10) >= 4 || (index & ~0x10) < 0) { |
| 3039 |
error(getPos(), "Bad DCT Huffman table"); |
3074 |
error(getPos(), "Bad DCT Huffman table"); |
| 3040 |
return gFalse; |
3075 |
return gFalse; |
| 3041 |
} |
3076 |
} |
| 3042 |
if (index & 0x10) { |
3077 |
if (index & 0x10) { |
| 3043 |
index &= 0x0f; |
3078 |
index &= 0x03; |
| 3044 |
if (index >= numACHuffTables) |
3079 |
if (index >= numACHuffTables) |
| 3045 |
numACHuffTables = index+1; |
3080 |
numACHuffTables = index+1; |
| 3046 |
tbl = &acHuffTables[index]; |
3081 |
tbl = &acHuffTables[index]; |
|
Lines 3833-3838
FlateStream::FlateStream(Stream *strA, i
Link Here
|
| 3833 |
FilterStream(strA) { |
3868 |
FilterStream(strA) { |
| 3834 |
if (predictor != 1) { |
3869 |
if (predictor != 1) { |
| 3835 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
3870 |
pred = new StreamPredictor(this, predictor, columns, colors, bits); |
|
|
3871 |
if (!pred->isOk()) { |
| 3872 |
delete pred; |
| 3873 |
pred = NULL; |
| 3874 |
} |
| 3836 |
} else { |
3875 |
} else { |
| 3837 |
pred = NULL; |
3876 |
pred = NULL; |
| 3838 |
} |
3877 |
} |