ajrcarey / pdfium-render

A high-level idiomatic Rust wrapper around Pdfium, the C++ PDF library used by the Google Chromium project.
https://crates.io/crates/pdfium-render
Other
341 stars 52 forks source link

FPDF_RenderPageBitmap" failed: JsValue(RuntimeError: call_indirect to a null table entry (evaluating 'asm[name].apply(null,arguments) #125

Closed reyjexter closed 10 months ago

reyjexter commented 10 months ago

Hello,

We ran into this issue with some documents when using Safari (both desktop and iphone). The web stack trace is as follow.

image

This doesn't happen on all documents and can occur only on certain documents. Also this only appears to happen on Safari but not Chrome and Brave browser.

It appears that the issue occurs somewhere when retrieving the image data on this function:

https://github.com/reyjexter/pdfium-render-wasm/blob/master/src/lib.rs#L89

Note: I haven't attached the pdf on which this error occurs as I'm still asking for an approval due to document may content sensitive data but hopefully if this error will help.

Thanks

EDIT: Made some edits on extra text I pasted.

ajrcarey commented 10 months ago

Hi @reyjexter , the error is thrown here: https://github.com/ajrcarey/pdfium-render/blob/master/src/wasm.rs#L401

Please switch on debugging output in your initialization of pdfium-render, as shown at https://github.com/ajrcarey/pdfium-render/blob/master/examples/index.html#L65, and provide those logs. Additionally, when filing any bug report for any project, please provide the versions of all relevant software; in this case, your Safari version and the source and version of your WASM Pdfium build.

reyjexter commented 10 months ago

Here's the software that we use:

MacOS - 14.1.1 (23B81) Sonoma Version 17.1 (19616.2.9.11.7) WASM Pdfium: V5407 pdfium-render: master branch Pdf size: 500 KB Rust & Cargo 1.73.0

I also attached the stack trace that is shown on log.

stacktrace.txt

reyjexter commented 10 months ago

We were able to replicate the issue with a test document and the issue appears to be happening if you create a PDF that included rounded corners. Here's the document which is a Canva generated document:

https://github.com/reyjexter/pdfium-render-wasm/blob/master/www/panic.pdf

ajrcarey commented 10 months ago

Possibly related to https://bugs.webkit.org/show_bug.cgi?id=263913

ajrcarey commented 10 months ago

Multiple webkit WASM bugs appear related to incorrect interpretation of LLVM optimisations. You could consider using the --dev profile when compiling your Rust code to WASM using wasmpack to disable optimisations:

https://rustwasm.github.io/wasm-pack/book/commands/build.html#profile

Apple's support for the latest version of LLVM tends to be rather poor (at least, if XCode's LLVM support is anything to go by). You could experiment with using an older version of Rust to compile your application (e.g. 1.60.0), as this would use an older verson of LLVM to perform the compilation.

As this is almost certainly a Safari (i.e. webkit)-specific problem, there's probably not going to be much I can do to help you from within pdfium-render.

ajrcarey commented 10 months ago

I cannot reproduce the problem using your test document on either Firefox or Chromium on Arch Linux, although based on what we know so far that isn't surprising.

Since all indications are that this is not a bug in pdfium-render but rather a problem with Apple's implementation of webkit, I will close the issue shortly if there are no further comments.

reyjexter commented 10 months ago

It looks like this is indeed a webkit issue. From our tests, this is already fixed on the new Safari 17.2 Beta4 and this change log probably fixed that:

https://developer.apple.com/documentation/safari-release-notes/safari-17_2-release-notes#Web-Assembly

Prior to testing on the 17.2 Beta4 Safari, we also tried compiling on Mac and Linux from 1.74 down to 1.61 and the issue didn't got fixed.

Thanks for providing the details especially the link to webkit issue as it was very useful to track this down.

ajrcarey commented 10 months ago

Thank you for the update - that's good news about Safari 17.2.