From 9de94991e9268ef1b017a065c7554c785bb736b2 Mon Sep 17 00:00:00 2001 From: benbro Date: Fri, 13 Jul 2012 17:41:20 +0300 Subject: [PATCH 1/3] Catch errors when parsing the linearization header so we can display corrupted docs --- src/core.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core.js b/src/core.js index 8e07078ef..5faac7621 100644 --- a/src/core.js +++ b/src/core.js @@ -398,10 +398,16 @@ var PDFDocument = (function PDFDocumentClosure() { get linearization() { var length = this.stream.length; var linearization = false; - if (length) { - linearization = new Linearization(this.stream); - if (linearization.length != length) - linearization = false; + try { + if (length) { + linearization = new Linearization(this.stream); + if (linearization.length != length) + linearization = false; + } + } catch (err) { + warn('since pdf is broken pdf.js is trying to recover it ' + + 'by indexing the object; ' + + 'the error in firebug shall have a different origin'); } // shadow the prototype getter with a data property return shadow(this, 'linearization', linearization); From 278dc81a5404377889af7f6ecaf4bebb7e4b7304 Mon Sep 17 00:00:00 2001 From: benbro Date: Fri, 13 Jul 2012 18:00:55 +0300 Subject: [PATCH 2/3] Move the try/catch block deeper --- src/core.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core.js b/src/core.js index 5faac7621..46c265298 100644 --- a/src/core.js +++ b/src/core.js @@ -398,16 +398,16 @@ var PDFDocument = (function PDFDocumentClosure() { get linearization() { var length = this.stream.length; var linearization = false; - try { - if (length) { + if (length) { + try { linearization = new Linearization(this.stream); if (linearization.length != length) linearization = false; + } catch (err) { + warn('since pdf is broken pdf.js is trying to recover it ' + + 'by indexing the object; ' + + 'the error in firebug shall have a different origin'); } - } catch (err) { - warn('since pdf is broken pdf.js is trying to recover it ' + - 'by indexing the object; ' + - 'the error in firebug shall have a different origin'); } // shadow the prototype getter with a data property return shadow(this, 'linearization', linearization); From a63814e2b920394db9f888de86a05559ad1ef182 Mon Sep 17 00:00:00 2001 From: benbro Date: Fri, 13 Jul 2012 18:09:20 +0300 Subject: [PATCH 3/3] Changed warning --- src/core.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core.js b/src/core.js index 46c265298..409ae060d 100644 --- a/src/core.js +++ b/src/core.js @@ -404,9 +404,8 @@ var PDFDocument = (function PDFDocumentClosure() { if (linearization.length != length) linearization = false; } catch (err) { - warn('since pdf is broken pdf.js is trying to recover it ' + - 'by indexing the object; ' + - 'the error in firebug shall have a different origin'); + warn('The linearization data is not available ' + + 'or unreadable pdf data is found'); } } // shadow the prototype getter with a data property