Properly handle errors when trying to open too large (>2GB-1) PDF file
(cherry picked from commit e9c6c76e79
)
This commit is contained in:
parent
13d22a2dbc
commit
a5c17f3abe
2 changed files with 23 additions and 1 deletions
|
@ -271,6 +271,10 @@ class PDFWorker {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let path = await attachment.getFilePathAsync();
|
let path = await attachment.getFilePathAsync();
|
||||||
|
let fileSize = (await OS.File.stat(path)).size;
|
||||||
|
if (fileSize > Math.pow(2, 31) - 1) {
|
||||||
|
throw new Error(`The file "${path}" is too large`);
|
||||||
|
}
|
||||||
let buf = await OS.File.read(path, {});
|
let buf = await OS.File.read(path, {});
|
||||||
buf = new Uint8Array(buf).buffer;
|
buf = new Uint8Array(buf).buffer;
|
||||||
|
|
||||||
|
@ -341,6 +345,10 @@ class PDFWorker {
|
||||||
|
|
||||||
async processCitaviAnnotations(pdfPath, citaviAnnotations, isPriority, password) {
|
async processCitaviAnnotations(pdfPath, citaviAnnotations, isPriority, password) {
|
||||||
return this._enqueue(async () => {
|
return this._enqueue(async () => {
|
||||||
|
let fileSize = (await OS.File.stat(pdfPath)).size;
|
||||||
|
if (fileSize > Math.pow(2, 31) - 1) {
|
||||||
|
throw new Error(`The file "${pdfPath}" is too large`);
|
||||||
|
}
|
||||||
let buf = await OS.File.read(pdfPath, {});
|
let buf = await OS.File.read(pdfPath, {});
|
||||||
buf = new Uint8Array(buf).buffer;
|
buf = new Uint8Array(buf).buffer;
|
||||||
try {
|
try {
|
||||||
|
@ -371,6 +379,10 @@ class PDFWorker {
|
||||||
*/
|
*/
|
||||||
async processMendeleyAnnotations(pdfPath, mendeleyAnnotations, isPriority, password) {
|
async processMendeleyAnnotations(pdfPath, mendeleyAnnotations, isPriority, password) {
|
||||||
return this._enqueue(async () => {
|
return this._enqueue(async () => {
|
||||||
|
let fileSize = (await OS.File.stat(pdfPath)).size;
|
||||||
|
if (fileSize > Math.pow(2, 31) - 1) {
|
||||||
|
throw new Error(`The file "${pdfPath}" is too large`);
|
||||||
|
}
|
||||||
let buf = await OS.File.read(pdfPath, {});
|
let buf = await OS.File.read(pdfPath, {});
|
||||||
buf = new Uint8Array(buf).buffer;
|
buf = new Uint8Array(buf).buffer;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -107,6 +107,14 @@ class ReaderInstance {
|
||||||
// Set `ReaderTab` title as fast as possible
|
// Set `ReaderTab` title as fast as possible
|
||||||
this.updateTitle();
|
this.updateTitle();
|
||||||
let path = await item.getFilePathAsync();
|
let path = await item.getFilePathAsync();
|
||||||
|
// Check file size, otherwise we get uncatchable error:
|
||||||
|
// JavaScript error: resource://gre/modules/osfile/osfile_native.jsm, line 60: RangeError: invalid array length
|
||||||
|
// See more https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length
|
||||||
|
let fileSize = (await OS.File.stat(path)).size;
|
||||||
|
// Max ArrayBuffer size before fx89 is 2GB-1 bytes
|
||||||
|
if (fileSize > Math.pow(2, 31) - 1) {
|
||||||
|
throw new Error(`The file "${path}" is too large`);
|
||||||
|
}
|
||||||
let buf = await OS.File.read(path, {});
|
let buf = await OS.File.read(path, {});
|
||||||
buf = new Uint8Array(buf).buffer;
|
buf = new Uint8Array(buf).buffer;
|
||||||
let annotationItems = item.getAnnotations();
|
let annotationItems = item.getAnnotations();
|
||||||
|
@ -153,7 +161,9 @@ class ReaderInstance {
|
||||||
}
|
}
|
||||||
|
|
||||||
uninit() {
|
uninit() {
|
||||||
this._prefObserverIDs.forEach(id => Zotero.Prefs.unregisterObserver(id));
|
if (this._prefObserverIDs) {
|
||||||
|
this._prefObserverIDs.forEach(id => Zotero.Prefs.unregisterObserver(id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get itemID() {
|
get itemID() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue