Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/image_picker/image_picker_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.8.13+22

* Fixes a crash when the content provider returns no stream for a picked
image; the pick now fails with `missing_valid_image_uri` instead.

## 0.8.13+21

* Updates pigeon dev_dependency to ^27.3.2 for analyzer 14 compatibility.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ class FileUtils {
*/
String getPathFromUri(final Context context, final Uri uri) {
try (InputStream inputStream = context.getContentResolver().openInputStream(uri)) {
if (inputStream == null) {
// `ContentResolver#openInputStream()` returns null when the provider cannot serve the
// item (for example after the provider crashed, or for a cloud-only photo it could not
// fetch). Treat it like any other unreadable item: no path, so the caller reports
// `missing_valid_image_uri` instead of crashing on the null stream.
return null;
}
String uuid = UUID.randomUUID().toString();
File targetDirectory = new File(context.getCacheDir(), uuid);
targetDirectory.mkdir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ public void FileUtil_GetPathFromUri() throws IOException {
assertEquals("imageStream", imageStream);
}

@Test
public void FileUtil_GetPathFromUri_nullStream() throws IOException {
Uri uri = Uri.parse("content://dummy/dummy.png");

// `openInputStream` returns null when the provider cannot serve the item; this used to
// reach `copy()` and crash the plugin's executor thread with a NullPointerException.
ContentResolver mockContentResolver = mock(ContentResolver.class);
when(mockContentResolver.openInputStream(any(Uri.class))).thenReturn(null);

Context mockContext = mock(Context.class);
when(mockContext.getContentResolver()).thenReturn(mockContentResolver);

String path = fileUtils.getPathFromUri(mockContext, uri);

assertNull(path);
}

@Test
public void FileUtil_GetPathFromUri_securityException() throws IOException {
Uri uri = Uri.parse("content://dummy/dummy.png");
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: image_picker_android
description: Android implementation of the image_picker plugin.
repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.13+21
version: 0.8.13+22

environment:
sdk: ^3.12.0
Expand Down
Loading