Bug 707966

Summary: Applying redactions render Preview-created PDFs incorrectly
Product: MuPDF Reporter: Jorj <jorj.x.mckie>
Component: mupdfAssignee: Robin Watts <robin.watts>
Status: RESOLVED FIXED    
Severity: normal CC: jamie.lemon, robin.watts
Priority: P2    
Version: unspecified   
Hardware: Macintosh   
OS: All   
Customer: Word Size: ---
Attachments: displays_badly_in_firefox.pdf

Description Jorj 2024-08-21 12:53:04 UTC
PyMuPDF issue: https://github.com/pymupdf/PyMuPDF/issues/3751
Problem file: https://github.com/user-attachments/files/16644815/output.pdf
    (and others in that issue post)

Problem description:
When a PDF was created using the Mac app "Preview", any redaction applied on some page, will display the resulting page incorrectly under Preview and some other, mostly Mac-related applications (UPDF, Safari browser among them).
The same page is displayed correctly on Adobe Acrobat, MuPDF, SumatraPDF, evince (Linux), Chrome browser, Edge browser and most other PDF viewers.

Firefox browser (Linux and Windows) also display the page erroneously ... however:
When saving the PDF with the clean and pretty option (which inserts white space / line breaks between appearance commands), the page will be again shown correctly in Firefox again.
But Preview and other Mac apps will continue to exhibit the problem.

Overall, this problem starts occurring with MuPDF 1.24 - versions before this behave as expected.
Comment 1 Robin Watts 2024-10-07 10:29:21 UTC
I've reduced one of the problem files so Firefox on Windows shows the problem, and Acrobat et al do not.

This fragment:

0 59.375 371.875 40.625 re
371.875 59.375 2106.25 40.625 re
0 3409.375 2306.25 40.625 re
2306.25 3409.375 171.875 40.625 re
115.625 115.625 2246.875 3275 re
.24 0 0 -.24 0 841.92 cm W* n
637.5 0 0 -259.375 140.625 550 cm
/Im1 Do

shows badly on Firefox, whereas if we move the cm operations to the top, it displays fine:

.24 0 0 -.24 0 841.92 cm W* n
637.5 0 0 -259.375 140.625 550 cm
0 59.375 371.875 40.625 re
371.875 59.375 2106.25 40.625 re
0 3409.375 2306.25 40.625 re
2306.25 3409.375 171.875 40.625 re
115.625 115.625 2246.875 3275 re
/Im1 Do
Comment 2 Robin Watts 2024-10-07 10:30:05 UTC
Created attachment 26111 [details]
displays_badly_in_firefox.pdf
Comment 3 Robin Watts 2024-10-18 13:53:07 UTC
This is believed to be fixed in the latest version, and was due to matrix changes after a path was defined, and before it was used.