Merge pull request #8909 from Snuffleupagus/PDFFunction-isEvalSupported

Check `isEvalSupported`, and test that `eval` is actually supported, before attempting to use the `PostScriptCompiler` (issue 5573)
This commit is contained in:
Tim van der Meij 2017-09-16 16:11:03 +02:00 committed by GitHub
commit 3be941d982
5 changed files with 32 additions and 9 deletions

View File

@ -24,6 +24,7 @@ import { OperatorList, PartialEvaluator } from './evaluator';
import { AnnotationFactory } from './annotation';
import { calculateMD5 } from './crypto';
import { Linearization } from './parser';
import { PDFFunction } from './function';
var Page = (function PageClosure() {
@ -532,6 +533,9 @@ var PDFDocument = (function PDFDocumentClosure() {
},
};
this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
let evaluatorOptions = this.pdfManager.evaluatorOptions;
PDFFunction.setIsEvalSupported(evaluatorOptions.isEvalSupported);
},
get numPages() {
var linearization = this.linearization;

View File

@ -54,6 +54,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
disableFontFace: false,
nativeImageDecoderSupport: NativeImageDecoding.DECODE,
ignoreErrors: false,
isEvalSupported: true,
};
function NativeImageDecoder(xref, resources, handler, forceDataSchema) {

View File

@ -13,17 +13,31 @@
* limitations under the License.
*/
import { FormatError, info, isBool } from '../shared/util';
import {
FormatError, info, isBool, isEvalSupported, shadow
} from '../shared/util';
import { isDict, isStream } from './primitives';
import { PostScriptLexer, PostScriptParser } from './ps_parser';
let IsEvalSupportedCached = {
get value() {
return shadow(this, 'value', isEvalSupported());
},
};
var PDFFunction = (function PDFFunctionClosure() {
var CONSTRUCT_SAMPLED = 0;
var CONSTRUCT_INTERPOLATED = 2;
var CONSTRUCT_STICHED = 3;
var CONSTRUCT_POSTSCRIPT = 4;
let isEvalSupported = true;
return {
setIsEvalSupported(support = true) {
isEvalSupported = support !== false;
},
getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
str) {
var i, ii;
@ -399,15 +413,17 @@ var PDFFunction = (function PDFFunctionClosure() {
var range = IR[2];
var code = IR[3];
var compiled = (new PostScriptCompiler()).compile(code, domain, range);
if (compiled) {
// Compiled function consists of simple expressions such as addition,
// subtraction, Math.max, and also contains 'var' and 'return'
// statements. See the generation in the PostScriptCompiler below.
// eslint-disable-next-line no-new-func
return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
if (isEvalSupported && IsEvalSupportedCached.value) {
let compiled = (new PostScriptCompiler()).compile(code, domain, range);
if (compiled) {
// Compiled function consists of simple expressions such as addition,
// subtraction, Math.max, and also contains 'var' and 'return'
// statements. See the generation in the PostScriptCompiler below.
// eslint-disable-next-line no-new-func
return new Function('src', 'srcOffset', 'dest', 'destOffset',
compiled);
}
}
info('Unable to compile PS function');
var numOutputs = range.length >> 1;

View File

@ -602,6 +602,7 @@ var WorkerMessageHandler = {
disableFontFace: data.disableFontFace,
nativeImageDecoderSupport: data.nativeImageDecoderSupport,
ignoreErrors: data.ignoreErrors,
isEvalSupported: data.isEvalSupported,
};
getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {

View File

@ -357,6 +357,7 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
docBaseUrl: source.docBaseUrl,
nativeImageDecoderSupport: source.nativeImageDecoderSupport,
ignoreErrors: source.ignoreErrors,
isEvalSupported: getDefaultSetting('isEvalSupported'),
}).then(function (workerId) {
if (worker.destroyed) {
throw new Error('Worker was destroyed');