mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
48.46k stars 9.98k forks source link

[Bug]: iOS browser crashed when loading some pdfs #18985

Closed KKzLEO closed 2 hours ago

KKzLEO commented 2 hours ago

Attach (recommended) or Link to PDF file

test.pdf

Web browser and its version

chrome 130.0.6723.78

Operating system and its version

iOS 18.0.1

PDF.js version

v4.7.76

Is the bug present in the latest PDF.js version?

Yes

Is a browser extension

No

Steps to reproduce the problem

  1. Go to https://mozilla.github.io/pdf.js/web/viewer.html
  2. open test.pdf I provided
  3. After loading a few pages, the entire browser crashed

https://github.com/user-attachments/assets/765f2e4a-be7f-4f7e-8c5a-a734d014d7d8 https://github.com/user-attachments/assets/4a9d6166-2ff3-4ffc-ad1d-c922a556e5ba

What is the expected behavior?

Do not crash

What went wrong?

crash

Link to a viewer

No response

Additional context

No response

Snuffleupagus commented 2 hours ago

That PDF contains quite large images (one per page), which require a fair amount of memory to decode, and it seems that this is simply running into limits in iOS itself (which isn't uncommon on that platform).

Unfortunately it's not entirely clear what we can really do about this here, and please note that Safari[1] is only listed as "mostly" supported in https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support


[1] Note that on iOS, all browsers are essentially built upon Safari.

KKzLEO commented 2 hours ago

@Snuffleupagus .Thank you for your response and the hard work your team is putting in. I am curious about the cause of this issue, especially since other PDFs with larger image sizes are functioning correctly. I also tried loading the pages one by one by removing the previous pages and adding new ones. Initially, this approach worked well, but it crashed after a few pages. Generally, I believe other pages should be garbage collected, correct? However, this doesn't seem to work effectively in Safari. Could there be memory leak issues with PDF.js? Other PDF frameworks, such as PSPDFKit, seem to perform well.

KKzLEO commented 15 minutes ago

Hello @Snuffleupagus , I hope you're doing well. It seems that this issue might not be exclusive to Safari, as other PDF.js-based libraries, such as PDF.js Express, are working correctly. Could you kindly consider reopening this issue? Thank you for your attention.