Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Downloading a password protected file gives SecurityException.class #160

Open
Gaawk opened this issue Oct 3, 2024 · 5 comments
Open
Labels
bug Something isn't working

Comments

@Gaawk
Copy link

Gaawk commented Oct 3, 2024

📝 Describe the Bug

When calling initWithUrl with the url of the pdf file which is password protected, app crashed for Security Exception. Do we have any way to open password protected file without crashing it?

📖 Library Version

  • PDF Viewer Version: [e.g., 2.0.0]

🚶 StackTrace

FATAL EXCEPTION: main
java.lang.SecurityException: password required or incorrect password
at android.graphics.pdf.PdfRenderer.nativeCreate(Native Method)
at android.graphics.pdf.PdfRenderer.(PdfRenderer.java:172)
at com.rajat.pdfviewer.PdfRendererCore.(PdfRendererCore.kt:72)
at com.rajat.pdfviewer.PdfRendererView.init(PdfRendererView.kt:147)
at com.rajat.pdfviewer.PdfRendererView.init(PdfRendererView.kt:142)
at com.rajat.pdfviewer.PdfDownloader$download$2$2.invokeSuspend(PdfDownloader.kt:101)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:257)
at android.os.Looper.loop(Looper.java:368)
at android.app.ActivityThread.main(ActivityThread.java:8839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:572)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@85f94c3, Dispatchers.Main.immediate]

@Gaawk Gaawk added the bug Something isn't working label Oct 3, 2024
Copy link

github-actions bot commented Oct 3, 2024

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!

@SolomonJesurathinam
Copy link

SolomonJesurathinam commented Oct 14, 2024

// Open pdf with password
private void openPDFWithPassword(File file, String password) throws IOException {
fileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
LoadParams loadParams = null;
if (android.os.ext.SdkExtensions.getExtensionVersion(android.os.Build.VERSION_CODES.S) >= 13) {
loadParams = new LoadParams.Builder()
.setPassword(password)
.build();
pdfRenderer = new PdfRendererPreV(fileDescriptor, loadParams);
}
}

This code works fine for me in android 11+ with sdk 35 (java), Can anyone please use this code and compile for kotlin for this library.

@afreakyelf
Copy link
Owner

Unfortunately password protected file is not supported at the moment.
@SolomonJesurathinam LoadParams was added in API 35, it would be inconsistent behaviour for older version If I used this.

@SolomonJesurathinam
Copy link

@afreakyelf I have done this for Android 11+, the PrerenderV supports from Android 11+. It works fine, I don't know about Kotlin, maybe you can check it once and incorporate it in your library.

@afreakyelf
Copy link
Owner

It works well with kotlin too but API has to be 35.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants
@SolomonJesurathinam @afreakyelf @Gaawk and others