pdf.js: PDFs with form fields crash in Safari
The following PDFs from the test/pdfs/
directory crash the viewer in Safari:
test/pdfs/160F-2019.pdf
test/pdfs/annotation-text-widget.pdf
test/pdfs/issue12963.pdf
test/pdfs/issue6127.pdf
test/pdfs/prefilled_f1040.pdf
Affected version
-
Commit: a17bd1302
-
Date: 2021-07-13
-
pdfjs.config
:{ "betaVersion": "2.9.359", "stableVersion": "2.8.335", "baseVersion": "e667c8cbcf8a8368dfab5eccb6b6f7999f1ae275", "versionPrefix": "2.10." }
Affected platforms
Safari on the following OS’s:
- MacOS 11.4 Big Sur (Safari 14.1.1)
- iPadOS 14.6
- iOS 14.6
Steps to reproduce
-
Install and then run web server:
$ git clone https://github.com/mozilla/pdf.js.git $ cd pdf.js $ npm install $ gulp server
-
Open http://localhost:8888/test/pdfs/?frame in Safari.
-
Click on top link in list, for
160F-2019.pdf
Expected result
File 160F-2019.pdf
is rendered correctly.
Actual result
The web page crashes with the error:
A problem repeatedly occurred with "localhost:8888/test/pdfs/?frame"
There are no errors logged in the JavaScript console.
Additional notes
-
Here is a .gif showing the issue:
-
These PDFs load properly and also have (some) form fields:
test/pdfs/annotation-tx.pdf
test/pdfs/annotation-tx2.pdf
test/pdfs/annotation-tx3.pdf
test/pdfs/bug1669099.pdf
test/pdfs/doc_actions.pdf
test/pdfs/evaljs.pdf
test/pdfs/issue12504.pdf
test/pdfs/issue12706.pdf
test/pdfs/issue12750.pdf
test/pdfs/issue13269.pdf
test/pdfs/issue13271.pdf
test/pdfs/issue9972-1.pdf
test/pdfs/issue9972-2.pdf
test/pdfs/issue9972-3.pdf
test/pdfs/js-authors.pdf
test/pdfs/js-buttons.pdf
test/pdfs/js-colors.pdf
test/pdfs/listbox_actions.pdf
test/pdfs/pr12828.pdf
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (2 by maintainers)
I tracked down the cause of the crash to this line:
https://github.com/mozilla/pdf.js/blob/51f0a810851c311598748f637fb583b20b7dce03/src/display/annotation_layer.js#L900
The following PDFs from the
test/pdfs/
directory will no longer crash the viewer in Safari with that line commented out (although letter spacing is now messed up in certain cases):It seems that Safari’s CSS
calc
function can’t handlech
units inletter-spacing
.I created a minimum test for this, in case anyone with access to Safari wants to try it out:
I installed the Safari Technology Preview for Big Sur from here: https://developer.apple.com/safari/download/ and the bug is fixed there. For reference, I think this WebKit bug report and patch might be related to the crashing behavior:
I have no idea when Safari will actually see this fix. In the meantime, the crashing behavior is present across MacOS, iOS and iPadOS.
Given https://github.com/mozilla/pdf.js/issues/13726#issuecomment-929517624 let’s close this issue here, since:
I can confirm that the CSS bug is now fixed in Safari 15 on:
I put up a page for people to easily check if their browser version has this bug:
https://jhacksworth.github.io/safari-css-bug-test.html
That page won’t load properly for browser versions with the bug.
Can’t we just replace
1ch
by0.5em
? (see https://developer.mozilla.org/en-US/docs/Web/CSS/length#ch)