Closed Bug 1978317 Opened 8 months ago Closed 7 months ago

HTML Spec page printed to PDF cannot be opened in Firefox

Categories

(Firefox :: PDF Viewer, defect, P1)

Desktop
All
defect

Tracking

()

VERIFIED FIXED
143 Branch
Tracking Status
firefox-esr140 --- verified
firefox141 --- wontfix
firefox142 --- wontfix
firefox143 --- verified

People

(Reporter: csasca, Assigned: calixte)

References

Details

Attachments

(2 files)

Found in

  • Firefox 142.0a1

Affected versions

  • Firefox 141.0
  • Firefox 142.0a1

Tested platforms

  • Affected platforms: Windows 11, Ubuntu 24
  • Unaffected platforms: macOS 15.5

Steps to reproduce

  1. Access this page
  2. Open the print preview and wait for the preview to fully load
  3. Print the page to PDF
  4. Open the printed PDF with Firefox

Expected result

  • The PDF is loaded in Firefox

Actual result

  • The PDF is not loaded in Firefox

Regression range

Additional notes

  • Print preview will take some time to be shown as there are ~1000 pages to load
  • Nothing is shown in browser console

The generated pdf fails to open in Firefox because of Invalid Root reference..
I can open it correctly in Chrome and PDFBox but not in Acrobat (where I got There was an error opening this document. The root object is missing or invalid.)
If I uncompress the pdf with qpdf then the result can be open in Firefox.
So there's something wrong in the pdf structure which should be workaround-able but the size of the pdf doesn't help to make the problem easy to figure out.
:Jonathan, would you have any idea on how we could find out what's wrong ?

Flags: needinfo?(jfkthame)

I think I found what's wrong with this pdf.
For the root object, in the xref table we've that it belongs the cross reference stream 282446 at index 4588.
But in the N entry of this xref stream, the reference of the pointed object is 14527 (which is a link annotation).
If the xref table would have been correct, the index would have been 266732.
I'll try to find a fix for this bug (we could use the data at the beginning of the stream with the pairs reference/offset), but for sure there is bug in Cairo here, cc :Jonathan.

Severity: -- → S3
Priority: -- → P3

Thanks for looking into this! Yes, sounds like this is caused by a bug in the Cairo PDF backend. We could really use some kind of reduced/simplified testcase if we're going to get this addressed upstream, though; we can hardly expect the Cairo developers to debug the generation of a thousand-page document via Firefox's printing code.

I wonder if the issue is triggered by the overall size of the output, or the number of pages, or some specific part of the content, or some other combination of factors....

Flags: needinfo?(jfkthame)

I tried a couple of experiments:

(a) Created an HTML doc that generates 1000 pages, but they're really simple: just a large box and a page number. Save to PDF (on Linux) results in a file of about 550K which Firefox can then re-open just fine. So it's not the page count (alone, at least) that leads to the problem.

(b) Used Chromium to save the HTML spec to a PDF. That resulted in a 994-page PDF that is over 90MB. But it still loads fine in Firefox. So it's not the large file size (alone) that leads to the problem, either.

(c) With the Chromium-generated PDF of the HTML spec opened in Firefox, used our Save to PDF to generate a new PDF copy. This is still a 994-page PDF, of course (because pagination doesn't change when we're dealing with a PDF original), but is only 22MB. This file can be re-opened in Firefox without problems. (Visually, it looks OK, but I note that the links that were in the original spec, and worked in the Chromium-generated PDF, are no longer present in this version.)

I notice you've got a pdf.js patch up - cool! If we do apply a workaround there, we should file a followup about the problem on the pdf-generation side. We'll still be potentially creating broken PDFs that fail to load in various other applications, even if pdf.js is able to handle them.

(In reply to Jonathan Kew [:jfkthame] from comment #6)

I notice you've got a pdf.js patch up - cool! If we do apply a workaround there, we should file a followup about the problem on the pdf-generation side. We'll still be potentially creating broken PDFs that fail to load in various other applications, even if pdf.js is able to handle them.

Yeah and the crazy thing is that it doesn't break our ref tests... I'm really surprised tbh :).

Anyway, after some debugging I found that: the first wrong reference is 141676, it's index in the xref stream is 65536 and the index found in the xref table is 0.
For an object in a xref stream, it should be referenced in the xref table as the xref stream reference followed by the index in the xref stream.
Usually the second number in the xref table is the generation number. The gen number is 5 digits, its min is 0, its max value is 65535 and there is a special meaning for 65535 (the ref cannot be reused). So usually the gen number is stored on 2 bytes which is very likely why we've this issue.
So I guess having a single web page with enough links should trigger the issue.

Assignee: nobody → cdenizet
Status: NEW → ASSIGNED
Priority: P3 → P1
No longer depends on: 1979423
Status: ASSIGNED → RESOLVED
Closed: 7 months ago
Resolution: --- → FIXED
Target Milestone: --- → 143 Branch

The patch landed in nightly and beta is affected.
:calixte, is this bug important enough to require an uplift?

For more information, please visit BugBot documentation.

Flags: needinfo?(cdenizet)

It's a corner case bug with pdfs containing a lot of links and which have been created in using Firefox on Windows or Linux.

QA Whiteboard: [qa-found-in-c142][S4] → [qa-found-in-c142][S4] [qa-triage-done-c144/b143] [qa-ver-needed-c144/b143]
Flags: qe-verify+

We're nominating bug 1970805 for esr140 uplift; if we take that, I think we should probably consider uplifting this as well.

Flags: needinfo?(cdenizet)
Attachment #9508527 - Flags: approval-mozilla-esr140?

firefox-esr140 Uplift Approval Request

  • User impact if declined: Some users printing large HTML to pdf won't be able to open them
  • Code covered by automated testing: yes
  • Fix verified in Nightly: no
  • Needs manual QE test: yes
  • Steps to reproduce for manual QE testing: See comment#0
  • Risk associated with taking this patch: Low
  • Explanation of risk level: It's a corner case
  • String changes made/needed: no
  • Is Android affected?: yes
Flags: needinfo?(cdenizet)
Attachment #9508527 - Flags: approval-mozilla-esr140? → approval-mozilla-esr140+

I've repro this issue with an affected Nightly build (2025-07-21) on Win 11.

The issue is verified as fixed on Win 11 and Ubuntu 24.04 using Firefox 143.0 and Esr 140.3.0.

Status: RESOLVED → VERIFIED
QA Whiteboard: [qa-found-in-c142][S4] [qa-triage-done-c144/b143] [qa-ver-needed-c144/b143] → [qa-found-in-c142][S4] [qa-triage-done-c144/b143] [qa-ver-done-c144/b143]
Flags: qe-verify+

I've forgotten to add this. cdenizet, while checking this issue, we noticed that PDFs take a long time to load in Firefox. In Edge, for example, they load much faster. Is this a known issue, or should we file a new bug for it?

Flags: needinfo?(cdenizet)

(In reply to Ciprian Georgiu, Desktop QA from comment #15)

I've forgotten to add this. cdenizet, while checking this issue, we noticed that PDFs take a long time to load in Firefox. In Edge, for example, they load much faster. Is this a known issue, or should we file a new bug for it?

Yep, I noticed that while debugging the file and it's mainly due having a bit too much annotations in the file and a too big struct tree.
:Ciprian, yes can file a bug please.

Flags: needinfo?(cdenizet)

(In reply to Calixte Denizet (:calixte) from comment #16)

(In reply to Ciprian Georgiu, Desktop QA from comment #15)

I've forgotten to add this. cdenizet, while checking this issue, we noticed that PDFs take a long time to load in Firefox. In Edge, for example, they load much faster. Is this a known issue, or should we file a new bug for it?

Yep, I noticed that while debugging the file and it's mainly due having a bit too much annotations in the file and a too big struct tree.
:Ciprian, yes can file a bug please.

Thanks! Filed bug 1987914.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: