1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Prevent the deprecated 'dotsection' command in Type1C to hit the sanitizer

This commit is contained in:
Vivien Nicolas 2011-09-11 15:23:35 +02:00
parent 7fa63e68dd
commit bcd8619414
3 changed files with 59 additions and 18 deletions

View file

@ -560,7 +560,7 @@ var CFFDictDataMap = {
'18': {
name: 'ExpansionFactor'
},
'9': {
'19': {
name: 'initialRandomSeed'
},
'20': {

View file

@ -20,17 +20,27 @@ function readCharset(aStream, aCharstrings) {
var charset = {};
var format = aStream.getByte();
var count = aCharstrings.length - 1;
if (format == 0) {
charset['.notdef'] = readCharstringEncoding(aCharstrings[0]);
var count = aCharstrings.length - 1;
for (var i = 1; i < count + 1; i++) {
var sid = aStream.getByte() << 8 | aStream.getByte();
charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[i]);
//log(CFFStrings[sid] + "::" + charset[CFFStrings[sid]]);
}
} else if (format == 1) {
error('Charset Range are not supported');
for (var i = 1; i < count + 1; i++) {
var first = aStream.getByte();
first = (first << 8) | aStream.getByte();
var numLeft = aStream.getByte();
for (var j = 0; j <= numLeft; j++) {
var sid = first++;
if (CFFStrings[sid] == 'three')
log(aCharstrings[j]);
charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[j]);
}
}
} else {
error('Invalid charset format');
}
@ -44,6 +54,9 @@ function readCharset(aStream, aCharstrings) {
* chapter 3.1.
*/
function readCharstringEncoding(aString) {
if (!aString)
return "";
var charstringTokens = [];
var count = aString.length;
@ -71,9 +84,9 @@ function readCharstringEncoding(aString) {
} else if (value < 247) {
token = parseInt(value) - 139;
} else if (value < 251) {
token = ((value - 247) * 256) + aString[i++] + 108;
token = (value - 247) * 256 + aString[i++] + 108;
} else if (value < 255) {
token = -((value - 251) * 256) - aString[i++] - 108;
token = -(value - 251) * 256 - aString[i++] - 108;
} else {// value == 255
token = aString[i++] << 24 | aString[i++] << 16 |
aString[i++] << 8 | aString[i];
@ -146,9 +159,9 @@ function readFontDictData(aString, aMap) {
} else if (value <= 246) {
token = parseInt(value) - 139;
} else if (value <= 250) {
token = ((value - 247) * 256) + aString[i++] + 108;
token = (value - 247) * 256 + aString[i++] + 108;
} else if (value <= 254) {
token = -((value - 251) * 256) - aString[i++] - 108;
token = -(value - 251) * 256 - aString[i++] - 108;
} else if (value == 255) {
error('255 is not a valid DICT command');
}
@ -199,7 +212,7 @@ function readFontIndexData(aStream, aIsByte) {
for (var i = 0; i < count + 1; i++)
offsets.push(getNextOffset());
log('Found ' + count + ' objects at offsets :' +
dump('Found ' + count + ' objects at offsets :' +
offsets + ' (offsize: ' + offsize + ')');
// Now extract the objects
@ -285,23 +298,20 @@ var Type2Parser = function(aFilePath) {
font.set('hdrSize', aStream.getByte());
font.set('offsize', aStream.getByte());
// Move the cursor after the header
aStream.skip(font.get('hdrSize') - aStream.pos);
// Read the NAME Index
dump('Reading Index: Names');
font.set('Names', readFontIndexData(aStream));
log('Names: ' + font.get('Names'));
dump('Names: ' + font.get('Names'));
// Read the Top Dict Index
dump('Reading Index: TopDict');
var topDict = readFontIndexData(aStream, true);
log('TopDict: ' + topDict);
dump('TopDict: ' + topDict);
// Read the String Index
dump('Reading Index: Strings');
var strings = readFontIndexData(aStream);
log('strings: ' + strings);
dump('strings: ' + strings);
// Fill up the Strings dictionary with the new unique strings
for (var i = 0; i < strings.length; i++)
@ -321,7 +331,7 @@ var Type2Parser = function(aFilePath) {
// Reading Private Dict
var priv = font.get('Private');
log('Reading Private Dict (offset: ' + priv.offset +
dump('Reading Private Dict (offset: ' + priv.offset +
' size: ' + priv.size + ')');
aStream.pos = priv.offset;