Skip to content

[fromContentUri] Null/short path causes substring crash #4477

Description

@wassdak

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-FileOperationsRelated to file operations (e.g. moving, copying, renaming).Issue-BugRelated unexpected behavior or something worth investigating.Issue-Easy (good first issue)Beginners welcome! Issues with relative low difficulty.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions