afreakyelf / Pdf-Viewer

A Lightweight PDF Viewer Android library which only occupies around 80kb while most of the Pdf viewer occupies up to 16MB space.
https://afreakyelf.github.io/Pdf-Viewer/
MIT License
809 stars 171 forks source link

Improve Error Handling when receiving invalid PDF #138

Open LarsWigger opened 5 months ago

LarsWigger commented 5 months ago

I just spent quit a bit of time debugging the PdfRendererView.initWithUrl() call because the app kept crashing when trying to load a specific PDF. In the end, the issue was that the server sent a 302 with a small HTML message when using the default headers (while accepting the default headers of every single other client I tried).

While this was not an issue on the side of Pdf-Viewer, I found the error handling pretty unhelpful and it definitely should not allow the app to crash when such a thing happens. I encountered two separate issues: The download silently failing because it was incomplete (I think the statusListener did not react to this, even though I saw the error messages in the logs) and the main issue of the app crashing when the data received was actually not a PDF document.

I suggest trying to download invalid data and checking whether the error handling is graceful and the error logging can be improved.

github-actions[bot] commented 5 months ago

Thank you for creating your first issue. We appreciate your help in making this project better. We will look into it, and get back to you soon. Need help or want to discuss this issue? Join our Discord community here to ask questions and discuss this issue live!

github-actions[bot] commented 4 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 4 months ago

This issue was closed because it has been stalled for 5 days with no activity.

afreakyelf commented 3 months ago

Thank you for the feedback. I will increase error handling.

foodpoison commented 2 months ago

I have this issue too, a client tried to load a file that's not a PDF but have .pdf as extension, which causes the app to crash; the line the crash happened is outside of the try..catch block so there's no way for us to handle this