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

  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

About this issue

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

Most upvoted comments

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.

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.

I have no idea when Safari will actually see this fix. In the meantime, the crashing behavior is present across MacOS, iOS and iPadOS.

I can confirm that the CSS bug is now fixed in Safari 15 on:

  • macOS (available for Big Sur & Catalina)
  • iPadOS 15
  • iOS 15

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 by 0.5em ? (see https://developer.mozilla.org/en-US/docs/Web/CSS/length#ch)