Uri.getFileName crashes when content providers reject metadata queries or return an empty cursor
Categories
(Firefox for Android :: Downloads, defect, P2)
Tracking
()
People
(Reporter: corentin, Assigned: corentin)
References
(Blocks 1 open bug)
Details
(Keywords: crash, Whiteboard: [fxdroid][android-activation-trust] )
Attachments
(1 file)
When handling a result from the Android file picker, FilePicker.handleFilePickerIntentResult() calls enqueueForCleanup() so that the temporary file can be deleted later. enqueueForCleanup() attempts to get the file name by calling Uri.getFileName(), but some content providers can throw an exception at this step:
ContentResolver.query()can throwIllegalArgumentExceptionCursorWrapper.getString()can throwCursorIndexOutOfBoundsExceptionif the cursor is empty
These exceptions happen before Firefox processes the selected file, so the upload is interrupted and Firefox crashes.
Example stacks:
java.lang.IllegalArgumentException
at android.database.DatabaseUtils.readExceptionFromParcel
at android.content.ContentProviderProxy.query
at android.content.ContentResolver.query
at mozilla.components.support.ktx.android.net.UriKt.getFileName
at mozilla.components.feature.prompts.file.FilePicker.enqueueForCleanup
android.database.CursorIndexOutOfBoundsException
at android.database.AbstractCursor.checkPosition
at android.database.AbstractWindowedCursor.getString
at android.database.CursorWrapper.getString
at mozilla.components.support.ktx.android.net.UriKt.getFileName
at mozilla.components.feature.prompts.file.FilePicker.enqueueForCleanup
Expected behavior
Failure to retrieve filename metadata should not crash Firefox. Such exceptions should be either caught, or a fallback file name should be generated to process so that the uploaded file is processed
Any additional information?
These exceptions were noticed when investigation this bug. These are ones of many causes of java.lang.RuntimeException: at android.app.ActivityThread.deliverResults described in this meta ticket
Updated•1 month ago
|
| Assignee | ||
Updated•1 month ago
|
| Assignee | ||
Updated•1 month ago
|
| Assignee | ||
Comment 1•1 month ago
|
||
FilePicker.enqueueForCleanup() calls Uri.getFileName() to name the temporary file that will be deleted later. Content URIs are processed in getFileNameForContentUris(), which used to query the content provider for OpenableColumns.DISPLAY_NAME column without accounting for some failures:
- ContentResolver.query() re throws whatever the content provider throws. For instance, an unrecognized URI can be rejected with an IllegalArgumentException
- moveToFirst() returns a boolean telling whether the move succeeded. This value was ignored and getString() could be called with an invalid cursor position, leading to a CursorIndexOutOfBoundsException
Both cases made Firefox crash. getFileNameForContentUris() now checks moveToFirst() result before calling getString(), and treats a RuntimeException from the query or from the cursor read as "no name available". A fallback name is now generated once, at the end of the function.
New unit tests have been added to cover these cases. The existing tests covering getFileNameForContentUris() have been renamed to use GIVEN ... WHEN ... THEN ... form for consistency.
Updated•1 month ago
|
| Assignee | ||
Updated•1 month ago
|
Comment 3•1 month ago
|
||
| bugherder | ||
| Assignee | ||
Comment 4•1 month ago
|
||
[Tracking Requested - why for this release]: Fixed an issue that could cause Firefox to crash when selecting files from some Android file providers.
| Assignee | ||
Comment 5•1 month ago
|
||
Release Note Request (optional, but appreciated)
[Why is this notable]:
[Affects Firefox for Android]:
[Suggested wording]: Fixed an issue that could cause Firefox to crash when selecting files from some Android file providers.
[Links (documentation, blog post, etc)]:
Comment 6•1 month ago
|
||
Thanks, added to the Fx156 nightly release notes, please allow 30 minutes for the site to update.
Description
•