Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue #373: handle bad encoding expcetion by start page renderin… #378

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions base/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ var Page = (function PageClosure() {
return promise;
},
getOperatorList: function Page_getOperatorList(handler) {
var self = this;
var promise = new Promise();

function reject(e) {
Expand All @@ -148,8 +147,7 @@ var Page = (function PageClosure() {
var pageListPromise = new Promise();

var pdfManager = this.pdfManager;
var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
[]);
var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
var resourcesPromise = this.loadResources([
'ExtGState',
'ColorSpace',
Expand All @@ -166,35 +164,31 @@ var Page = (function PageClosure() {
this.pageIndex, 'p' + this.pageIndex + '_',
this.idCounters, this.fontCache);

var dataPromises = Promise.all(
[contentStreamPromise, resourcesPromise], reject);
dataPromises.then(function(data) {
Promise.all([contentStreamPromise, resourcesPromise]).then(function(data) {
var contentStream = data[0];


var opList = new OperatorList(handler, self.pageIndex);
try {
handler.send('StartRenderPage', {
transparency: partialEvaluator.hasBlendModes(self.resources),
pageIndex: self.pageIndex
});
partialEvaluator.getOperatorList(contentStream, self.resources, opList);
pageListPromise.resolve(opList);
}
catch(e) {
pageListPromise.reject(e);
}
});
try {
var opList = new OperatorList(handler, this.pageIndex);
partialEvaluator.getOperatorList(contentStream, this.resources, opList);
pageListPromise.resolve(opList);

handler.send('StartRenderPage', {
transparency: partialEvaluator.hasBlendModes(this.resources),
pageIndex: this.pageIndex
});
} catch (ex) {
reject(ex);
}
}.bind(this), reject);

var annotationsPromise = pdfManager.ensure(this, 'annotations');
Promise.all([pageListPromise, annotationsPromise]).then(function(datas) {
var pageOpList = datas[0];
var annotations = datas[1];
Promise.all([pageListPromise, annotationsPromise]).then(function(data) {
var pageOpList = data[0];
var annotations = data[1];

if (annotations.length === 0) {
pageOpList.flush(true);
promise.resolve(pageOpList);
return;
return promise;
}

var annotationsReadyPromise = Annotation.appendToOperatorList(
Expand Down
21 changes: 10 additions & 11 deletions base/display/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,18 @@ var Metadata = (PDFJS.Metadata = (function MetadataClosure() {
}

function Metadata(meta) {
if (typeof meta === 'string') {
this.metadata = {};
if (typeof meta === 'string') {
// Ghostscript produces invalid metadata
meta = fixMetadata(meta);

var parser = new DOMParser();
meta = parser.parseFromString(meta, 'application/xml');
} else if (!(meta instanceof Document)) {
error('Metadata: Invalid metadata object');
}

this.metaDocument = meta;
this.metadata = {};
this.parse();
meta = meta.trim();
if (meta.startsWith('<') && meta.endsWith('>')) {
var parser = new DOMParser();
meta = parser.parseFromString(meta, 'application/xml');
this.metaDocument = meta;
this.parse();
}
}
}

Metadata.prototype = {
Expand Down
4 changes: 2 additions & 2 deletions base/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ function error(msg) {
} else {
//log('Error: ' + msg);
}
//log(backtrace());
//PDFJS.LogManager.notify('error', msg);
// log(backtrace());
PDFJS.LogManager.notify('error', msg);
throw new Error(msg);
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"test:jest": "jest --config ./jest.config.json",
"test": "jest --config ./jest.config.json && npm run parse-r && npm run parse-fd",
"test:forms": "cd ./test && sh p2j.forms.sh",
"test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 13 success, 4 fail exception with stack trace\" ",
"test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 13 success, 5 fail exception with stack trace\" ",
"parse": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form",
"parse-s": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s",
"parse-t": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s -t",
Expand All @@ -48,7 +48,7 @@
"parse-tb": "./bin/pdf2json.js -f ./test/pdf/misc/i242_testingWithTable.pdf -o ./test/target/misc",
"parse-tc": "./bin/pdf2json.js -f ./test/pdf/misc/i293_pdfpac.pdf -o ./test/target/misc",
"parse-rectFix": "./bin/pdf2json.js -f ./test/pdf/misc/pr298_rect_fix_from_upstream.pdf -o ./test/target/misc",
"parse-e": "./bin/pdf2json.js -f ./test/pdf/misc/i43_encrypted.pdf -o ./test/target/misc",
"parse-e": "./bin/pdf2json.js -f ./test/pdf/misc/i373_err_broken.pdf -o ./test/target/misc",
"build:rollup": "rollup -c ./rollup.config.js",
"build:bundle-pdfjs-base": "node rollup/bundle-pdfjs-base.js",
"build": "npm run build:bundle-pdfjs-base && npm run build:rollup",
Expand Down
Binary file added test/pdf/misc/i373_err_broken.pdf
Binary file not shown.
Loading