question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PDFs with form fields crash in Safari

See original GitHub issue

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

  1. Install and then run web server:

     $ git clone https://github.com/mozilla/pdf.js.git
     $ cd pdf.js
     $ npm install
     $ gulp server
    
  2. Open http://localhost:8888/test/pdfs/?frame in Safari.

  3. 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: screen600

  • 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jhacksworthcommented, Jul 24, 2021

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):

test/pdfs/160F-2019.pdf
test/pdfs/annotation-text-widget.pdf
test/pdfs/issue12963.pdf
test/pdfs/issue6127.pdf
test/pdfs/prefilled_f1040.pdf

It seems that Safari’s CSS calc function can’t handle ch units in letter-spacing.

I created a minimum test for this, in case anyone with access to Safari wants to try it out:

<!doctype html>
<html>
    <head>
        <title>CSS calc() with ch units</title>
        <style>
         #fail {letter-spacing: calc(1ch);}
        </style>
    </head>
    <body>
        <h1 id="fail">This will cause a crash</h1>
    </body>
</html>

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.

1reaction
Snuffleupaguscommented, Sep 29, 2021

Given https://github.com/mozilla/pdf.js/issues/13726#issuecomment-929517624 let’s close this issue here, since:

  • This was clearly a browser bug, which has now been fixed. Given that a single line of very simple CSS was enough to “crash” the browser, you’d really hope that previous versions of Safari will be patched as well.
  • Historically, in the PDF.js project, we’ve always been reluctant to add browser-specific compatibility hacks in the main code-base for reasons of readability/maintainability/performance.
  • This only affects a small number of PDF documents, when Safari is used, since the document needs to contain forms and also have “comb”-fields.
Read more comments on GitHub >

github_iconTop Results From Across the Web

ALL PDF files crash Safari! - Apple Community
2) Go into the Safari settings (very glad these are outside of the app) and Clear Cache. This immediately solves the problem because...
Read more >
Fill & Sign Crashing since update
Every time I open any pdf file, select fill & sign, & select me as who is editing, within a few seconds the...
Read more >
Known issues | Acrobat, Reader - Adobe Support
Forms. Problem: Fields from the dropdown menu do not get placed on the ... when PDF is launched in the Safari browser (version...
Read more >
Third-Party Compatibility - PSPDFKit
Apple uses a custom PDF renderer (CGPDF) that's part of Core Graphics. It's quite capable, but it is known to crash/freeze or not...
Read more >
Troubleshooting | Help Center
Mac iOS In case the file can't be opened and instead you see the message about it being corrupted, these are the first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found