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:
commit
1d82521b4c
@ -283,7 +283,6 @@ var Catalog = (function CatalogClosure() {
|
|||||||
var pageLabels = new Array(this.numPages);
|
var pageLabels = new Array(this.numPages);
|
||||||
var style = null;
|
var style = null;
|
||||||
var prefix = '';
|
var prefix = '';
|
||||||
var start = 1;
|
|
||||||
|
|
||||||
var numberTree = new NumberTree(obj, this.xref);
|
var numberTree = new NumberTree(obj, this.xref);
|
||||||
var nums = numberTree.getAll();
|
var nums = numberTree.getAll();
|
||||||
@ -300,14 +299,16 @@ var Catalog = (function CatalogClosure() {
|
|||||||
|
|
||||||
var s = labelDict.get('S');
|
var s = labelDict.get('S');
|
||||||
assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
|
assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
|
||||||
style = (s ? s.name : null);
|
style = s ? s.name : null;
|
||||||
|
|
||||||
prefix = labelDict.get('P') || '';
|
var p = labelDict.get('P');
|
||||||
assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
|
assert(!p || isString(p), 'Invalid prefix in PageLabel dictionary.');
|
||||||
|
prefix = p ? stringToPDFString(p) : '';
|
||||||
|
|
||||||
start = labelDict.get('St') || 1;
|
var st = labelDict.get('St');
|
||||||
assert(isInt(start), 'Invalid start in PageLabel dictionary.');
|
assert(!st || (isInt(st) && st >= 1),
|
||||||
currentIndex = start;
|
'Invalid start in PageLabel dictionary.');
|
||||||
|
currentIndex = st || 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (style) {
|
switch (style) {
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -40,6 +40,7 @@
|
|||||||
!issue7544.pdf
|
!issue7544.pdf
|
||||||
!issue7598.pdf
|
!issue7598.pdf
|
||||||
!issue7665.pdf
|
!issue7665.pdf
|
||||||
|
!bad-PageLabels.pdf
|
||||||
!filled-background.pdf
|
!filled-background.pdf
|
||||||
!ArabicCIDTrueType.pdf
|
!ArabicCIDTrueType.pdf
|
||||||
!ThuluthFeatures.pdf
|
!ThuluthFeatures.pdf
|
||||||
|
BIN
test/pdfs/bad-PageLabels.pdf
Normal file
BIN
test/pdfs/bad-PageLabels.pdf
Normal file
Binary file not shown.
@ -503,14 +503,24 @@ describe('api', function() {
|
|||||||
return pdfDoc.getPageLabels();
|
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[0]).toEqual(['i', 'ii', 'iii', '1']);
|
||||||
expect(pageLabels[1]).toEqual(['Front Page1']);
|
expect(pageLabels[1]).toEqual(['Front Page1']);
|
||||||
expect(pageLabels[2]).toEqual(['1', '2']);
|
expect(pageLabels[2]).toEqual(['1', '2']);
|
||||||
|
expect(pageLabels[3]).toEqual(['X1']);
|
||||||
|
|
||||||
loadingTask0.destroy();
|
loadingTask0.destroy();
|
||||||
loadingTask1.destroy();
|
loadingTask1.destroy();
|
||||||
loadingTask2.destroy();
|
loadingTask2.destroy();
|
||||||
|
loadingTask3.destroy();
|
||||||
done();
|
done();
|
||||||
}).catch(function (reason) {
|
}).catch(function (reason) {
|
||||||
done.fail(reason);
|
done.fail(reason);
|
||||||
|
Loading…
Reference in New Issue
Block a user