"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "xpdf/JBIG2Stream.cc" between
xpdf-4.01.01.tar.gz and xpdf-4.02.tar.gz

About: Xpdf is a PDF viewer for X.

JBIG2Stream.cc  (xpdf-4.01.01):JBIG2Stream.cc  (xpdf-4.02)
skipping to change at line 841 skipping to change at line 841
// check for the pathological case where y = -2^31 // check for the pathological case where y = -2^31
if (y < -0x7fffffff) { if (y < -0x7fffffff) {
return; return;
} }
if (y < 0) { if (y < 0) {
y0 = -y; y0 = -y;
} else { } else {
y0 = 0; y0 = 0;
} }
if (y > INT_MAX - bitmap->h) {
return;
}
if (y + bitmap->h > h) { if (y + bitmap->h > h) {
y1 = h - y; y1 = h - y;
} else { } else {
y1 = bitmap->h; y1 = bitmap->h;
} }
if (y0 >= y1) { if (y0 >= y1) {
return; return;
} }
if (x >= 0) { if (x >= 0) {
skipping to change at line 1205 skipping to change at line 1208
delete huffDecoder; delete huffDecoder;
delete mmrDecoder; delete mmrDecoder;
delete str; delete str;
} }
Stream *JBIG2Stream::copy() { Stream *JBIG2Stream::copy() {
return new JBIG2Stream(str->copy(), &globalsStream); return new JBIG2Stream(str->copy(), &globalsStream);
} }
void JBIG2Stream::reset() { void JBIG2Stream::reset() {
// read the globals stream GList *t;
segments = new GList();
globalSegments = new GList(); globalSegments = new GList();
// read the globals stream
if (globalsStream.isStream()) { if (globalsStream.isStream()) {
segments = globalSegments;
curStr = globalsStream.getStream(); curStr = globalsStream.getStream();
curStr->reset(); curStr->reset();
arithDecoder->setStream(curStr); arithDecoder->setStream(curStr);
huffDecoder->setStream(curStr); huffDecoder->setStream(curStr);
mmrDecoder->setStream(curStr); mmrDecoder->setStream(curStr);
readSegments(); readSegments();
curStr->close(); curStr->close();
// swap the newly read segments list into globalSegments
t = segments;
segments = globalSegments;
globalSegments = t;
} }
// read the main stream // read the main stream
segments = new GList();
curStr = str; curStr = str;
curStr->reset(); curStr->reset();
arithDecoder->setStream(curStr); arithDecoder->setStream(curStr);
huffDecoder->setStream(curStr); huffDecoder->setStream(curStr);
mmrDecoder->setStream(curStr); mmrDecoder->setStream(curStr);
readSegments(); readSegments();
if (pageBitmap) { if (pageBitmap) {
dataPtr = pageBitmap->getDataPtr(); dataPtr = pageBitmap->getDataPtr();
dataEnd = dataPtr + pageBitmap->getDataSize(); dataEnd = dataPtr + pageBitmap->getDataSize();
skipping to change at line 1283 skipping to change at line 1292
n = (int)(dataEnd - dataPtr); n = (int)(dataEnd - dataPtr);
} else { } else {
n = size; n = size;
} }
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
blk[i] = *dataPtr++ ^ 0xff; blk[i] = *dataPtr++ ^ 0xff;
} }
return n; return n;
} }
GString *JBIG2Stream::getPSFilter(int psLevel, const char *indent) { GString *JBIG2Stream::getPSFilter(int psLevel, const char *indent,
GBool okToReadStream) {
return NULL; return NULL;
} }
GBool JBIG2Stream::isBinary(GBool last) { GBool JBIG2Stream::isBinary(GBool last) {
return str->isBinary(gTrue); return str->isBinary(gTrue);
} }
void JBIG2Stream::readSegments() { void JBIG2Stream::readSegments() {
Guint segNum, segFlags, segType, page, segLength; Guint segNum, segFlags, segType, page, segLength;
Guint refFlags, nRefSegs; Guint refFlags, nRefSegs;
skipping to change at line 1509 skipping to change at line 1519
Guint huffDH, huffDW, huffBMSize, huffAggInst; Guint huffDH, huffDW, huffBMSize, huffAggInst;
Guint contextUsed, contextRetained; Guint contextUsed, contextRetained;
int sdATX[4], sdATY[4], sdrATX[2], sdrATY[2]; int sdATX[4], sdATY[4], sdrATX[2], sdrATY[2];
Guint numExSyms, numNewSyms, numInputSyms, symCodeLen; Guint numExSyms, numNewSyms, numInputSyms, symCodeLen;
JBIG2Bitmap **bitmaps; JBIG2Bitmap **bitmaps;
JBIG2Bitmap *collBitmap, *refBitmap; JBIG2Bitmap *collBitmap, *refBitmap;
Guint *symWidths; Guint *symWidths;
Guint symHeight, symWidth, totalWidth, x, symID; Guint symHeight, symWidth, totalWidth, x, symID;
int dh, dw, refAggNum, refDX, refDY, bmSize; int dh, dw, refAggNum, refDX, refDY, bmSize;
GBool ex; GBool ex;
int run, cnt; int run, prevRun, cnt;
Guint i, j, k; Guint i, j, k;
symWidths = NULL; symWidths = NULL;
// symbol dictionary flags // symbol dictionary flags
if (!readUWord(&flags)) { if (!readUWord(&flags)) {
goto eofError; goto eofError;
} }
sdTemplate = (flags >> 10) & 3; sdTemplate = (flags >> 10) & 3;
sdrTemplate = (flags >> 12) & 1; sdrTemplate = (flags >> 12) & 1;
skipping to change at line 1856 skipping to change at line 1866
delete collBitmap; delete collBitmap;
} }
} }
// create the symbol dict object // create the symbol dict object
symbolDict = new JBIG2SymbolDict(segNum, numExSyms); symbolDict = new JBIG2SymbolDict(segNum, numExSyms);
// exported symbol list // exported symbol list
i = j = 0; i = j = 0;
ex = gFalse; ex = gFalse;
prevRun = 1;
while (i < numInputSyms + numNewSyms) { while (i < numInputSyms + numNewSyms) {
if (huff) { if (huff) {
huffDecoder->decodeInt(&run, huffTableA); huffDecoder->decodeInt(&run, huffTableA);
} else { } else {
arithDecoder->decodeInt(&run, iaexStats); arithDecoder->decodeInt(&run, iaexStats);
} }
if (run == 0 && prevRun == 0) {
// this avoids infinite loops with damaged files (consecutive
// zero runs are never useful)
error(errSyntaxError, getPos(),
"Invalid exported symbol list in JBIG2 symbol dictionary");
delete symbolDict;
goto syntaxError;
}
if (i + run > numInputSyms + numNewSyms || if (i + run > numInputSyms + numNewSyms ||
(ex && j + run > numExSyms)) { (ex && j + run > numExSyms)) {
error(errSyntaxError, getPos(), error(errSyntaxError, getPos(),
"Too many exported symbols in JBIG2 symbol dictionary"); "Too many exported symbols in JBIG2 symbol dictionary");
delete symbolDict; delete symbolDict;
goto syntaxError; goto syntaxError;
} }
if (ex) { if (ex) {
for (cnt = 0; cnt < run; ++cnt) { for (cnt = 0; cnt < run; ++cnt) {
symbolDict->setBitmap(j++, bitmaps[i++]->copy()); symbolDict->setBitmap(j++, bitmaps[i++]->copy());
} }
} else { } else {
i += run; i += run;
} }
ex = !ex; ex = !ex;
prevRun = run;
} }
if (j != numExSyms) { if (j != numExSyms) {
error(errSyntaxError, getPos(), "Too few symbols in JBIG2 symbol dictionary" ); error(errSyntaxError, getPos(), "Too few symbols in JBIG2 symbol dictionary" );
delete symbolDict; delete symbolDict;
goto syntaxError; goto syntaxError;
} }
for (i = 0; i < numNewSyms; ++i) { for (i = 0; i < numNewSyms; ++i) {
delete bitmaps[numInputSyms + i]; delete bitmaps[numInputSyms + i];
} }
skipping to change at line 2146 skipping to change at line 2166
} }
delete codeTables; delete codeTables;
// symbol ID Huffman decoding table // symbol ID Huffman decoding table
if (huff) { if (huff) {
huffDecoder->reset(); huffDecoder->reset();
for (i = 0; i < 32; ++i) { for (i = 0; i < 32; ++i) {
runLengthTab[i].val = i; runLengthTab[i].val = i;
runLengthTab[i].prefixLen = huffDecoder->readBits(4); runLengthTab[i].prefixLen = huffDecoder->readBits(4);
runLengthTab[i].rangeLen = 0; runLengthTab[i].rangeLen = 0;
runLengthTab[i].prefix = 0;
} }
runLengthTab[32].val = 0x103; runLengthTab[32].val = 0x103;
runLengthTab[32].prefixLen = huffDecoder->readBits(4); runLengthTab[32].prefixLen = huffDecoder->readBits(4);
runLengthTab[32].rangeLen = 2; runLengthTab[32].rangeLen = 2;
runLengthTab[32].prefix = 0;
runLengthTab[33].val = 0x203; runLengthTab[33].val = 0x203;
runLengthTab[33].prefixLen = huffDecoder->readBits(4); runLengthTab[33].prefixLen = huffDecoder->readBits(4);
runLengthTab[33].rangeLen = 3; runLengthTab[33].rangeLen = 3;
runLengthTab[33].prefix = 0;
runLengthTab[34].val = 0x20b; runLengthTab[34].val = 0x20b;
runLengthTab[34].prefixLen = huffDecoder->readBits(4); runLengthTab[34].prefixLen = huffDecoder->readBits(4);
runLengthTab[34].rangeLen = 7; runLengthTab[34].rangeLen = 7;
runLengthTab[34].prefix = 0;
runLengthTab[35].prefixLen = 0; runLengthTab[35].prefixLen = 0;
runLengthTab[35].rangeLen = jbig2HuffmanEOT; runLengthTab[35].rangeLen = jbig2HuffmanEOT;
runLengthTab[35].prefix = 0;
huffDecoder->buildTable(runLengthTab, 35); huffDecoder->buildTable(runLengthTab, 35);
symCodeTab = (JBIG2HuffmanTable *)gmallocn(numSyms + 1, symCodeTab = (JBIG2HuffmanTable *)gmallocn(numSyms + 1,
sizeof(JBIG2HuffmanTable)); sizeof(JBIG2HuffmanTable));
for (i = 0; i < numSyms; ++i) { for (i = 0; i < numSyms; ++i) {
symCodeTab[i].val = i; symCodeTab[i].val = i;
symCodeTab[i].rangeLen = 0; symCodeTab[i].rangeLen = 0;
} }
i = 0; i = 0;
while (i < numSyms) { while (i < numSyms) {
huffDecoder->decodeInt(&j, runLengthTab); huffDecoder->decodeInt(&j, runLengthTab);
if (j > 0x200) { if (j > 0x200) {
for (j -= 0x200; j && i < numSyms; --j) { for (j -= 0x200; j && i < numSyms; --j) {
symCodeTab[i++].prefixLen = 0; symCodeTab[i++].prefixLen = 0;
} }
} else if (j > 0x100) { } else if (j > 0x100) {
if (i == 0) {
error(errSyntaxError, getPos(), "Invalid code in JBIG2 text region");
gfree(syms);
gfree(symCodeTab);
return;
}
for (j -= 0x100; j && i < numSyms; --j) { for (j -= 0x100; j && i < numSyms; --j) {
symCodeTab[i].prefixLen = symCodeTab[i-1].prefixLen; symCodeTab[i].prefixLen = symCodeTab[i-1].prefixLen;
++i; ++i;
} }
} else { } else {
symCodeTab[i++].prefixLen = j; symCodeTab[i++].prefixLen = j;
} }
} }
symCodeTab[numSyms].prefixLen = 0; symCodeTab[numSyms].prefixLen = 0;
symCodeTab[numSyms].rangeLen = jbig2HuffmanEOT; symCodeTab[numSyms].rangeLen = jbig2HuffmanEOT;
skipping to change at line 2229 skipping to change at line 2260
// clean up the Huffman decoder // clean up the Huffman decoder
if (huff) { if (huff) {
gfree(symCodeTab); gfree(symCodeTab);
} }
return; return;
codeTableError: codeTableError:
error(errSyntaxError, getPos(), "Missing code table in JBIG2 text region"); error(errSyntaxError, getPos(), "Missing code table in JBIG2 text region");
gfree(codeTables); delete codeTables;
delete syms; gfree(syms);
return; return;
eofError: eofError:
error(errSyntaxError, getPos(), "Unexpected EOF in JBIG2 stream"); error(errSyntaxError, getPos(), "Unexpected EOF in JBIG2 stream");
return; return;
} }
JBIG2Bitmap *JBIG2Stream::readTextRegion(GBool huff, GBool refine, JBIG2Bitmap *JBIG2Stream::readTextRegion(GBool huff, GBool refine,
int w, int h, int w, int h,
Guint numInstances, Guint numInstances,
 End of changes. 18 change blocks. 
7 lines changed or deleted 38 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)