Merge pull request #9594 from Snuffleupagus/pageLabel-validation

Add stricter validation in `Catalog.readPageLabels`
This commit is contained in:
Tim van der Meij 2018-03-24 19:40:49 +01:00 committed by GitHub
commit 115fbc47fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -263,33 +263,45 @@ var Catalog = (function CatalogClosure() {
for (var i = 0, ii = this.numPages; i < ii; i++) { for (var i = 0, ii = this.numPages; i < ii; i++) {
if (i in nums) { if (i in nums) {
var labelDict = nums[i]; const labelDict = nums[i];
if (!isDict(labelDict)) { if (!isDict(labelDict)) {
throw new FormatError('The PageLabel is not a dictionary.'); throw new FormatError('The PageLabel is not a dictionary.');
} }
var type = labelDict.get('Type'); if (labelDict.has('Type') &&
if (type && !isName(type, 'PageLabel')) { !isName(labelDict.get('Type'), 'PageLabel')) {
throw new FormatError('Invalid type in PageLabel dictionary.'); throw new FormatError('Invalid type in PageLabel dictionary.');
} }
var s = labelDict.get('S'); if (labelDict.has('S')) {
if (s && !isName(s)) { const s = labelDict.get('S');
throw new FormatError('Invalid style in PageLabel dictionary.'); if (!isName(s)) {
throw new FormatError('Invalid style in PageLabel dictionary.');
}
style = s.name;
} else {
style = null;
} }
style = s ? s.name : null;
var p = labelDict.get('P'); if (labelDict.has('P')) {
if (p && !isString(p)) { const p = labelDict.get('P');
throw new FormatError('Invalid prefix in PageLabel dictionary.'); if (!isString(p)) {
throw new FormatError('Invalid prefix in PageLabel dictionary.');
}
prefix = stringToPDFString(p);
} else {
prefix = '';
} }
prefix = p ? stringToPDFString(p) : '';
var st = labelDict.get('St'); if (labelDict.has('St')) {
if (st && !(Number.isInteger(st) && st >= 1)) { const st = labelDict.get('St');
throw new FormatError('Invalid start in PageLabel dictionary.'); if (!(Number.isInteger(st) && st >= 1)) {
throw new FormatError('Invalid start in PageLabel dictionary.');
}
currentIndex = st;
} else {
currentIndex = 1;
} }
currentIndex = st || 1;
} }
switch (style) { switch (style) {
@ -320,10 +332,10 @@ var Catalog = (function CatalogClosure() {
throw new FormatError( throw new FormatError(
`Invalid style "${style}" in PageLabel dictionary.`); `Invalid style "${style}" in PageLabel dictionary.`);
} }
currentLabel = '';
} }
pageLabels[i] = prefix + currentLabel;
currentLabel = ''; pageLabels[i] = prefix + currentLabel;
currentIndex++; currentIndex++;
} }
return pageLabels; return pageLabels;