Merge pull request #7782 from Snuffleupagus/page-labels-more-validation

Use `stringToPDFString` to sanitizing bad "Prefix" entries in Page Label dictionaries, and add more validation
This commit is contained in:
Tim van der Meij 2016-11-03 22:16:39 +01:00 committed by GitHub
commit 1d82521b4c
4 changed files with 20 additions and 8 deletions

View File

@ -283,7 +283,6 @@ var Catalog = (function CatalogClosure() {
var pageLabels = new Array(this.numPages);
var style = null;
var prefix = '';
var start = 1;
var numberTree = new NumberTree(obj, this.xref);
var nums = numberTree.getAll();
@ -300,14 +299,16 @@ var Catalog = (function CatalogClosure() {
var s = labelDict.get('S');
assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
style = (s ? s.name : null);
style = s ? s.name : null;
prefix = labelDict.get('P') || '';
assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
var p = labelDict.get('P');
assert(!p || isString(p), 'Invalid prefix in PageLabel dictionary.');
prefix = p ? stringToPDFString(p) : '';
start = labelDict.get('St') || 1;
assert(isInt(start), 'Invalid start in PageLabel dictionary.');
currentIndex = start;
var st = labelDict.get('St');
assert(!st || (isInt(st) && st >= 1),
'Invalid start in PageLabel dictionary.');
currentIndex = st || 1;
}
switch (style) {

View File

@ -40,6 +40,7 @@
!issue7544.pdf
!issue7598.pdf
!issue7665.pdf
!bad-PageLabels.pdf
!filled-background.pdf
!ArabicCIDTrueType.pdf
!ThuluthFeatures.pdf

Binary file not shown.

View File

@ -503,14 +503,24 @@ describe('api', function() {
return pdfDoc.getPageLabels();
});
Promise.all([promise0, promise1, promise2]).then(function (pageLabels) {
// PageLabels with bad "Prefix" entries.
var url3 = new URL('../pdfs/bad-PageLabels.pdf', window.location).href;
var loadingTask3 = new PDFJS.getDocument(url3);
var promise3 = loadingTask3.promise.then(function (pdfDoc) {
return pdfDoc.getPageLabels();
});
Promise.all([promise0, promise1, promise2, promise3]).then(
function (pageLabels) {
expect(pageLabels[0]).toEqual(['i', 'ii', 'iii', '1']);
expect(pageLabels[1]).toEqual(['Front Page1']);
expect(pageLabels[2]).toEqual(['1', '2']);
expect(pageLabels[3]).toEqual(['X1']);
loadingTask0.destroy();
loadingTask1.destroy();
loadingTask2.destroy();
loadingTask3.destroy();
done();
}).catch(function (reason) {
done.fail(reason);