AmazeFileManager icon indicating copy to clipboard operation
AmazeFileManager copied to clipboard

[fromContentUri] Null/short path causes substring crash

Open wassdak opened this issue 2 months ago • 2 comments

Affected Method (full signature): com.amaze.filemanager.filesystem.files.FileUtils.fromContentUri(@androidx.annotation.NonNull android.net.Uri uri)

Environment: • AmazeFileManager: stock release/4.0 • Robolectric/JVM

Steps to Reproduce (Robolectric-friendly): 1. Uri u = Uri.parse("content://com.example.provider/x"); (very short path) 2. Call File f = FileUtils.fromContentUri(u); 3. Method performs substring(FILE_PROVIDER_PREFIX.length() + 1) on uri.getPath() without length check.

Expected Behavior: Validate length and prefix before substring; gracefully reject/return fallback for malformed content URIs.

Actual Behavior: StringIndexOutOfBoundsException or NullPointerException when getPath() is null/short.

Minimal Input Example: android.net.Uri u = android.net.Uri.parse("content://com.example.provider/x"); java.io.File f = FileUtils.fromContentUri(u); // crash or invalid

Impact: Crashes when browsing or opening content documents with atypical but valid URIs.

Suggested Fix: Guard uri.getPath() for null/length, verify expected prefix before substring, and handle short paths with a safe fallback (or return null/throw a descriptive exception). Prefer robust parsing over fixed offsets.

wassdak avatar Nov 11 '25 02:11 wassdak

Hey @EmmanuelMess, Can I work on this bug?

siddhesh-06 avatar Dec 06 '25 06:12 siddhesh-06

Hey @EmmanuelMess, Can I work on this bug?

Yes please

TranceLove avatar Dec 06 '25 07:12 TranceLove