1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 07:38:07 +02:00

[api-minor] Always allow e.g. rendering to continue even if there are errors, and add a stopAtErrors parameter to getDocument to opt-out of this behaviour (issue 6342, issue 3795, bug 1130815)

Other PDF readers, e.g. Adobe Reader and PDFium (in Chrome), will attempt to render as much of a page as possible even if there are errors present.
Currently we just bail as soon the first error is hit, which means that we'll usually not render anything in these cases and just display a blank page instead.

NOTE: This patch changes the default behaviour of the PDF.js API to always attempt to recover as much data as possible, even when encountering errors during e.g. `getOperatorList`/`getTextContent`, which thus improve our handling of corrupt PDF files and allow the default viewer to handle errors slightly more gracefully.
In the event that an API consumer wishes to use the old behaviour, where we stop parsing as soon as an error is encountered, the `stopAtErrors` parameter can be set at `getDocument`.

Fixes, inasmuch it's possible since the PDF files are corrupt, e.g. issue 6342, issue 3795, and [bug 1130815](https://bugzilla.mozilla.org/show_bug.cgi?id=1130815) (and probably others too).
This commit is contained in:
Jonas Jenwald 2017-02-19 14:03:08 +01:00
parent 10e5f766a2
commit a39d636eb8
8 changed files with 255 additions and 50 deletions

View file

@ -21,6 +21,7 @@
!issue5874.pdf
!issue5808.pdf
!issue6204.pdf
!issue6342.pdf
!issue6652.pdf
!issue6782.pdf
!issue6901.pdf

View file

@ -0,0 +1 @@
https://bug1130815.bmoattachments.org/attachment.cgi?id=8560958

142
test/pdfs/issue6342.pdf Normal file
View file

@ -0,0 +1,142 @@
%PDF-1.7
%âãÏÓ
1 0 obj
<<
/Kids [2 0 R]
/Count 1
/Type /Pages
>>
endobj
2 0 obj
<<
/Group 3 0 R
/Parent 1 0 R
/Resources 4 0 R
/MediaBox [0 0 300 100]
/Type /Page
/Contents 5 0 R
>>
endobj
3 0 obj
<<
/CS /DeviceRGB
/Type /Group
/S /Transparency
>>
endobj
4 0 obj
<<
/Font
<<
/F1 6 0 R
>>
/XObject
<<
/Im1 7 0 R
>>
>>
endobj
5 0 obj
<<
/Length 193
>>
stream
q
1 0 0 1 10 80 cm
0 0 0 rg 0 0 0 RG
1 w
0 0 m
280 0 l S
Q
q
1 0 0 1 25 45 cm
/Im1 Do
1 0 0 1 100 0 cm
/Im1 Do
Q
q
1 0 0 1 10 20 cm
BT
/F1 18 Tf
(Issue 6342 - Form XObject with errors) Tj
ET
Q
endstream
endobj
7 0 obj
<<
/Group 3 0 R
/Subtype /Form
/Length 1050
/Resources
<<
/ExtGState
<<
/a0
<<
/ca 1
/CA 1
>>
>>
>>
/FormType 1
/BBox [0 0 45 25]
/Type /XObject
>>
stream
q
0.2 0.8 0.2 rg /a0 gs
13.117 22.651 m 11.281 22.651 9.809 21.163 9.809 19.327 c 9.809 18.733
9.961 18.174 10.234 17.69 c 11.34 18.315 12.621 18.678 13.98 18.678 c
14.113 18.678 14.238 18.674 14.367 18.666 c 14.352 18.85 14.344 19.038
14.344 19.229 c 14.344 20.252 14.566 21.225 14.957 22.1 c 14.43 22.455
13.801 22.651 13.117 22.651 c h
13.117 22.651 m f
6.383 12.92 m 2.859 12.92 0 10.084 0 6.561 c 0 3.034 2.859 0.174 6.383
0.174 c 7.727 0.174 8.969 0.592 9.996 1.299 c 9.57 1.959 9.32 2.748
9.32 3.584 .020.594 6. c 499 c08. c830.174 586.17 21.17436
8.4 6.17436 9 c030.1717436 9 c 18.6.418.85930784 07.859 05.1717c08.
859 09.6.442.859 12m f
6.383 12651 m f
6.383 12.9f
678 13.757 5.651727563.757 5.7.0 2.8 c858.7.0 2.8 c030.177.0 2.09 8
8.136.1778899 797 5.521265172496.17873.8 c90674 c95.65153174 c95.c.455 c 7.4 c95.651918.7.770.252105.7.74522.1 c047 61 18.67802 61623.67802 748069.229 c02 1 m 13.9 c719.651202 15c90678 c809.3215c195.654 18.6746 3.
117768.674469..75728.229 c 09..7578.6741452.757 5.678 13.757 5.651 c h 13.757 5.65f
Q
endstream
endobj
6 0 obj
<<
/BaseFont /Times-Roman
/Subtype /Type1
/Encoding /WinAnsiEncoding
/Type /Font
>>
endobj
8 0 obj
<<
/Pages 1 0 R
/Type /Catalog
>>
endobj xref
0 9
0000000000 65535 f
0000000015 00000 n
0000000074 00000 n
0000000193 00000 n
0000000261 00000 n
0000000334 00000 n
0000001818 00000 n
0000000581 00000 n
0000001919 00000 n
trailer
<<
/Root 8 0 R
/Size 9
>>
startxref
1969
%%EOF

View file

@ -1500,6 +1500,20 @@
"lastPage": 1,
"type": "load"
},
{ "id": "bug1130815-eq",
"file": "pdfs/bug1130815.pdf",
"md5": "3ff3b550c3af766991b2a1b11d00de85",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "bug1130815-text",
"file": "pdfs/bug1130815.pdf",
"md5": "3ff3b550c3af766991b2a1b11d00de85",
"rounds": 1,
"link": true,
"type": "text"
},
{ "id": "issue3248",
"file": "pdfs/issue3248.pdf",
"md5": "970767ed68de46c316d74de67965999b",
@ -1532,6 +1546,20 @@
"lastPage": 1,
"type": "load"
},
{ "id": "issue6342-eq",
"file": "pdfs/issue6342.pdf",
"md5": "2ea85ca8d17117798f105be88bdb2bfd",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue6342-text",
"file": "pdfs/issue6342.pdf",
"md5": "2ea85ca8d17117798f105be88bdb2bfd",
"rounds": 1,
"link": false,
"type": "text"
},
{ "id": "issue7020",
"file": "pdfs/issue7020.pdf",
"md5": "93b464e21c649e64ae92eeafe99fc31b",