Fixed
Status Update
Comments
ve...@google.com <ve...@google.com>
ve...@google.com <ve...@google.com> #2
We have passed this to the development team and will update this issue with more information as it becomes available.
ve...@google.com <ve...@google.com> #3
The development team has fixed the issue that you have reported and it will be available in a future.
Description
While we are able to successfully create PdfRenderer objects for other PDF files, they will always fail after the corrupted file is used to initialize a PdfRenderer object -
i.e. once the corrupted file is used, PdfRenderer fails to be created on subsequent initializations despite being successful previously.
DEVICE/VERSION:
Seeing on multiple, testing sample APK with HTC U11 on Android 8.0.0
STEPS TO REPRODUCE:
1) Create a PdfRenderer object with a corrupted PDF. Exception is thrown
2) Try to create PdfRenderer object with a valid PDF. Exception will be thrown if done after step 1, even though the file is valid and works if created before step 1
RELEVANT CODE:
private fun viewPdf() {
try {
val file = File(pdfLocation)
val parcelFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)
renderer = PdfRenderer(parcelFileDescriptor) ///< "file not in PDF format or corrupted" exception thrown here
binding.fragmentPreviewViewpager.adapter = PreviewPagerAdapter(renderer.pageCount, file)
renderer.close()
} catch(e: IOException) {
e.printStackTrace()
showAlert("Error loading PDF", e.message ?: "Exception thrown while loading pdf")
renderer?.close()
}
}
WHAT HAPPENED:
PdfRenderer class breaks for the rest of the app's lifetime if a corrupted PDF file is used to create a PdfRenderer object
CORRECT BEHAVIOR:
1) The "corrupted" pdf in our case opens just fine using other PDF viewers, including Drive PDF Viewer. We would expect it to open fine with PdfRenderer
2) More importantly, even if PdfRenderer throws an exception while initializing with a corrupted file, it should continue to work the next time an initialization attempt is made with a valid file
In the sample app you will find three files: (1) 8879_broken.pdf ; (2) 8879_ok.pdf ; (3) Nonsense.pdf
(1): This PDF is what 'breaks' the PdfRenderer class and makes any subsequent initialization attempt fail, even if the file is valid.
- Note that this PDF opens fine using other PDF viewers despite PdfRenderer claiming the file is corrupted
(2): This is the original PDF of (1), but it has not been corrupted. This file initializes just fine with the PdfRenderer object unless (1) has been initialized previously
(3): A PDF that initializes fine, unless (1) has been initialized previously
Note - our file storage server has a bug that appended text to the end of some of our files. We are seeing this on files (1) and (3) above. We're not sure if this is causing the initialization failure for (1) since (3) also contains this odd text appended to the end and it loads fine; however, the only discernible difference when comparing (1) and (2) above is the extra text that is appended to the end of the file in (1)
SAMPLE APP INSTRUCTIONS (minimum API 21):
1) On first launch, allow WRITE_EXTERNAL_STORAGE permission
2) Open "Nonsense.pdf" and verify that PDF loads. Return to list.
3) Open "8879_ok.pdf" and verify that PDF loads. Return to list.
4) Open "8879_broken.pdf". Notice "file not in PDF format or corrupted" exception message and failure to load. Return to list
5) Attempt to open either "Nonsense.pdf" or "8879_ok.pdf". Neither of these files will work now and show the same error
6) Kill app and try steps 2 & 3 - they should load fine again