mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Detect scripted auto-print requests
Fixes #6106 To avoid future regressions, two new unit tests were added: 1. A new PDF based on the report from #6106, which contains an OpenAction of type JavaScript and a string "this.print({...}". 2. An existing PDF from https://bugzil.la/1001080 (from #4698). Although it does not matter, since we don't execute the JavaScript code, I have also changed "print(true)" to "print({})" since the print method takes an object (not a boolean). See "Printing PDF documents", page 62: http://adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_developer_guide.pdf
This commit is contained in:
parent
d3e90cf825
commit
c676ecb5a0
6 changed files with 124 additions and 24 deletions
|
@ -534,6 +534,19 @@ var Catalog = (function CatalogClosure() {
|
|||
var obj = this.catDict.get('Names');
|
||||
|
||||
var javaScript = [];
|
||||
function appendIfJavaScriptDict(jsDict) {
|
||||
var type = jsDict.get('S');
|
||||
if (!isName(type) || type.name !== 'JavaScript') {
|
||||
return;
|
||||
}
|
||||
var js = jsDict.get('JS');
|
||||
if (isStream(js)) {
|
||||
js = bytesToString(js.getBytes());
|
||||
} else if (!isString(js)) {
|
||||
return;
|
||||
}
|
||||
javaScript.push(stringToPDFString(js));
|
||||
}
|
||||
if (obj && obj.has('JavaScript')) {
|
||||
var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
|
||||
var names = nameTree.getAll();
|
||||
|
@ -544,36 +557,25 @@ var Catalog = (function CatalogClosure() {
|
|||
// We don't really use the JavaScript right now. This code is
|
||||
// defensive so we don't cause errors on document load.
|
||||
var jsDict = names[name];
|
||||
if (!isDict(jsDict)) {
|
||||
continue;
|
||||
if (isDict(jsDict)) {
|
||||
appendIfJavaScriptDict(jsDict);
|
||||
}
|
||||
var type = jsDict.get('S');
|
||||
if (!isName(type) || type.name !== 'JavaScript') {
|
||||
continue;
|
||||
}
|
||||
var js = jsDict.get('JS');
|
||||
if (!isString(js) && !isStream(js)) {
|
||||
continue;
|
||||
}
|
||||
if (isStream(js)) {
|
||||
js = bytesToString(js.getBytes());
|
||||
}
|
||||
javaScript.push(stringToPDFString(js));
|
||||
}
|
||||
}
|
||||
|
||||
// Append OpenAction actions to javaScript array
|
||||
var openactionDict = this.catDict.get('OpenAction');
|
||||
if (isDict(openactionDict)) {
|
||||
var objType = openactionDict.get('Type');
|
||||
if (isDict(openactionDict, 'Action')) {
|
||||
var actionType = openactionDict.get('S');
|
||||
var action = openactionDict.get('N');
|
||||
var isPrintAction = (isName(objType) && objType.name === 'Action' &&
|
||||
isName(actionType) && actionType.name === 'Named' &&
|
||||
isName(action) && action.name === 'Print');
|
||||
|
||||
if (isPrintAction) {
|
||||
javaScript.push('print(true);');
|
||||
if (isName(actionType) && actionType.name === 'Named') {
|
||||
// The named Print action is not a part of the PDF 1.7 specification,
|
||||
// but is supported by many PDF readers/writers (including Adobe's).
|
||||
var action = openactionDict.get('N');
|
||||
if (isName(action) && action.name === 'Print') {
|
||||
javaScript.push('print({});');
|
||||
}
|
||||
} else {
|
||||
appendIfJavaScriptDict(openactionDict);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue