TeamAmaze / TeamAmaze/AmazeFileManager

Crash When Attempting to Open Read-Only Content in Read-Write Mode

Open
#1,015 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-FileOperations Issue-Bug
Dominant language
Kotlin
Stars
6.4k
Forks
1.7k
Avg merge
3d 9h
Merged PRs (30d)
1

Description

On Amaze 3.2.1, if another app starts an ACTION_VIEW Intent for text/plain and a valid Uri pointing to read-only content, TextReader crashes:

java.lang.SecurityException: Permission Denial: writing android.support.v4.content.FileProvider uri content://com.commonsware.myapplication.provider/Download/hello_world.txt from pid=592, uid=10170 requires the provider be exported, or grantUriPermission()
   at android.os.Parcel.readException(Parcel.java:2004)
   at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
   at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
   at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:625)
   at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1265)
   at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1100)
   at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1054)
   at com.amaze.filemanager.activities.TextReader.getInputStream(TextReader.java:685)
   at com.amaze.filemanager.activities.TextReader.access$400(TextReader.java:92)
   at com.amaze.filemanager.activities.TextReader$4.run(TextReader.java:461)

That comes from this code segment. I think that your algorithm is fine, but you need to check for SecurityException in addition to FileNotFoundException, and try the read-only access in both cases.

The attached sample project reproduces the problem. It is nearly the same as the one from issue #1014, except that this one fixes the null Uri problem that triggered that earlier crash. Like the first one, it requires a hello_world.txt file in the Download/ directory of external storage.

MyApplication-20180211b.zip

This can be reproduced on Android 8.1 at minimum, though I suspect that it will yield similar results on other modern versions of Android.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in app/src/main/java/com/amaze/filemanager/activities/TextReader.java around lines 681-700, especially getInputStream, and review the attached sample project's reproduction. Confirm the ACTION_VIEW path with a read-only text/plain Uri, then verify that the reader falls back to read-only access after the reported permission failure without crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.