mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #2298 from zalun/show_alert_on_invalid_pdf_structure
Display an error on Invalid PDF
This commit is contained in:
commit
ee87a44c03
7 changed files with 62 additions and 5 deletions
|
@ -539,6 +539,14 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||
this.workerReadyPromise.reject(data.exception.message, data.exception);
|
||||
}, this);
|
||||
|
||||
messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
|
||||
this.workerReadyPromise.reject(data.exception.name, data.exception);
|
||||
}, this);
|
||||
|
||||
messageHandler.on('UnknownError', function transportUnknownError(data) {
|
||||
this.workerReadyPromise.reject(data.exception.message, data.exception);
|
||||
}, this);
|
||||
|
||||
messageHandler.on('GetPage', function transportPage(data) {
|
||||
var pageInfo = data.pageInfo;
|
||||
var page = new PDFPageProxy(pageInfo, this);
|
||||
|
|
|
@ -574,7 +574,8 @@ var XRef = (function XRefClosure() {
|
|||
if (dict)
|
||||
return dict;
|
||||
// nothing helps
|
||||
error('Invalid PDF structure');
|
||||
// calling error() would reject worker with an UnknownErrorException.
|
||||
throw new InvalidPDFException('Invalid PDF structure');
|
||||
},
|
||||
readXRef: function XRef_readXRef(startXRef, recoveryMode) {
|
||||
var stream = this.stream;
|
||||
|
|
25
src/util.js
25
src/util.js
|
@ -148,6 +148,31 @@ var PasswordException = (function PasswordExceptionClosure() {
|
|||
return PasswordException;
|
||||
})();
|
||||
|
||||
var UnknownErrorException = (function UnknownErrorExceptionClosure() {
|
||||
function UnknownErrorException(msg, details) {
|
||||
this.name = 'UnknownErrorException';
|
||||
this.message = msg;
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
UnknownErrorException.prototype = new Error();
|
||||
UnknownErrorException.constructor = UnknownErrorException;
|
||||
|
||||
return UnknownErrorException;
|
||||
})();
|
||||
|
||||
var InvalidPDFException = (function InvalidPDFExceptionClosure() {
|
||||
function InvalidPDFException(msg) {
|
||||
this.name = 'InvalidPDFException';
|
||||
this.message = msg;
|
||||
}
|
||||
|
||||
InvalidPDFException.prototype = new Error();
|
||||
InvalidPDFException.constructor = InvalidPDFException;
|
||||
|
||||
return InvalidPDFException;
|
||||
})();
|
||||
|
||||
function bytesToString(bytes) {
|
||||
var str = '';
|
||||
var length = bytes.length;
|
||||
|
|
|
@ -124,9 +124,19 @@ var WorkerMessageHandler = {
|
|||
});
|
||||
}
|
||||
|
||||
return;
|
||||
} else if (e instanceof InvalidPDFException) {
|
||||
handler.send('InvalidPDF', {
|
||||
exception: e
|
||||
});
|
||||
|
||||
return;
|
||||
} else {
|
||||
throw e;
|
||||
handler.send('UnknownError', {
|
||||
exception: new UnknownErrorException(e.message, e.toString())
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
var doc = {
|
||||
|
@ -331,4 +341,3 @@ if (typeof window === 'undefined') {
|
|||
var handler = new MessageHandler('worker_processor', this);
|
||||
WorkerMessageHandler.setup(handler);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue