JBIG2: finds end of segment when length is not specified

This commit is contained in:
Yury Delendik 2013-02-23 08:04:17 -06:00
parent 007a643279
commit 1d4372775d
3 changed files with 43 additions and 2 deletions

View File

@ -710,9 +710,42 @@ var Jbig2Image = (function Jbig2ImageClosure() {
position += 4;
}
segmentHeader.length = readUint32(data, position);
if (segmentHeader.length == 0xFFFFFFFF)
error('JBIG2 error: unknown segment length is not supported');
position += 4;
if (segmentHeader.length == 0xFFFFFFFF) {
// 7.2.7 Segment data length, unknown segment length
if (segmentType === 38) { // ImmediateGenericRegion
var genericRegionInfo = readRegionSegmentInformation(data, position);
var genericRegionSegmentFlags = data[position +
RegionSegmentInformationFieldLength];
var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
// searching for the segment end
var searchPatternLength = 6;
var searchPattern = new Uint8Array(searchPatternLength);
if (!genericRegionMmr) {
searchPattern[0] = 0xFF;
searchPattern[1] = 0xAC;
}
searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
searchPattern[5] = genericRegionInfo.height & 0xFF;
for (var i = position, ii = data.length; i < ii; i++) {
var j = 0;
while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
j++;
}
if (j == searchPatternLength) {
segmentHeader.length = i + searchPatternLength;
break;
}
}
if (segmentHeader.length == 0xFFFFFFFF) {
error('JBIG2 error: segment end was not found');
}
} else {
error('JBIG2 error: invalid unknown segment length');
}
}
segmentHeader.headerEnd = position;
return segmentHeader;
}

View File

@ -0,0 +1 @@
http://www.cs.wustl.edu/~cytron/cse547/PDFs/p1.pdf

View File

@ -474,6 +474,13 @@
"link": true,
"type": "load"
},
{ "id": "issue2139",
"file": "pdfs/issue2139.pdf",
"md5": "ee4072992e7c5ffd5063181916a2fcae",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "issue1010",
"file": "pdfs/issue1010.pdf",
"md5": "f991ef093484a107fe9f59dff18fc155",