JBIG2: finds end of segment when length is not specified
This commit is contained in:
parent
007a643279
commit
1d4372775d
37
src/jbig2.js
37
src/jbig2.js
@ -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;
|
||||
}
|
||||
|
1
test/pdfs/issue2139.pdf.link
Normal file
1
test/pdfs/issue2139.pdf.link
Normal file
@ -0,0 +1 @@
|
||||
http://www.cs.wustl.edu/~cytron/cse547/PDFs/p1.pdf
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user