mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #3456 from brendandahl/cap-image-size
Limit image size to 1024*1024 for b2g.
This commit is contained in:
commit
077f08fa6d
5 changed files with 26 additions and 2 deletions
10
src/api.js
10
src/api.js
|
@ -21,6 +21,13 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* The maximum allowed image size in total pixels e.g. width * height. Images
|
||||
* above this value will not be drawn. Use -1 for no limit.
|
||||
* @var {Number}
|
||||
*/
|
||||
PDFJS.maxImageSize = PDFJS.maxImageSize === undefined ? -1 : PDFJS.maxImageSize;
|
||||
|
||||
/**
|
||||
* This is the main entry point for loading a PDF and interacting with it.
|
||||
* NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
|
||||
|
@ -760,7 +767,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
|
||||
this.messageHandler.send('GetDocRequest', {
|
||||
source: source,
|
||||
disableRange: PDFJS.disableRange
|
||||
disableRange: PDFJS.disableRange,
|
||||
maxImageSize: PDFJS.maxImageSize
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -234,6 +234,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
var w = dict.get('Width', 'W');
|
||||
var h = dict.get('Height', 'H');
|
||||
|
||||
if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
|
||||
warn('Image exceeded maximum allowed size and was removed.');
|
||||
return null;
|
||||
}
|
||||
|
||||
var dependencies = {};
|
||||
var retData = {
|
||||
dependencies: dependencies
|
||||
|
@ -706,6 +711,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
} else if ('Image' == type.name) {
|
||||
var data = self.buildPaintImageXObject(
|
||||
resources, xobj, false);
|
||||
if (!data) {
|
||||
args = [];
|
||||
continue;
|
||||
}
|
||||
Util.extendObj(dependencies, data.dependencies);
|
||||
self.insertDependencies(queue, data.dependencies);
|
||||
fn = data.fn;
|
||||
|
@ -720,6 +729,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
} else if (cmd == 'EI') {
|
||||
var data = self.buildPaintImageXObject(
|
||||
resources, args[0], true);
|
||||
if (!data) {
|
||||
args = [];
|
||||
continue;
|
||||
}
|
||||
Util.extendObj(dependencies, data.dependencies);
|
||||
self.insertDependencies(queue, data.dependencies);
|
||||
fn = data.fn;
|
||||
|
|
|
@ -307,6 +307,9 @@ var WorkerMessageHandler = {
|
|||
}
|
||||
};
|
||||
|
||||
PDFJS.maxImageSize = data.maxImageSize === undefined ?
|
||||
-1 : data.maxImageSize;
|
||||
|
||||
getPdfManager(data).then(function pdfManagerReady() {
|
||||
loadDocument(false).then(onSuccess, function loadFailure(ex) {
|
||||
// Try again with recoveryMode == true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue