Skip to content

[image_picker] Handle a null stream from openInputStream on Android - #12682

Closed
ralatorre wants to merge 1 commit into
flutter:mainfrom
ralatorre:image-picker-android-null-stream
Closed

ralatorre wants to merge 1 commit into
flutter:mainfrom
ralatorre:image-picker-android-null-stream

Conversation

@ralatorre

Copy link
Copy Markdown

ContentResolver#openInputStream() returns null when the provider cannot serve the picked item (a provider that crashed, a cloud-only photo it could not fetch). FileUtils.getPathFromUri opens the stream in a try-with-resources (where a null resource is legal) and hands it straight to copy(); the resulting NullPointerException on the delegate's executor thread is uncaught and kills the process. The null-URI sibling was guarded in #5009; the null-stream step right after it was not.

This returns null from getPathFromUri for a null stream, so the delegate reports the existing missing_valid_image_uri error exactly as it does for the other unreadable cases, and adds a unit test in the shape of the existing SecurityException one.

Fixes flutter/flutter#191988

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

`ContentResolver#openInputStream()` returns null when the provider
cannot serve the item (a provider that crashed, a cloud-only photo it
could not fetch). `FileUtils.getPathFromUri` passed that null into
`copy()`, and the resulting NullPointerException on the delegate's
executor thread killed the process (seen in the field on a Xiaomi device
running Android 10). Return null instead, so the delegate reports
`missing_valid_image_uri` as it does for the other unreadable cases.
@google-cla

google-cla Bot commented Aug 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ralatorre

Copy link
Copy Markdown
Author

Closing: I can't complete the CLA at this time. The analysis stays in the linked issue for anyone who wants to pick this up.

@ralatorre ralatorre closed this Aug 28, 2026
@ralatorre
ralatorre deleted the image-picker-android-null-stream branch August 28, 2026 22:25
auto-submit Bot pushed a commit that referenced this pull request Sep 10, 2026
Null safety when ContentResolver cannot open a stream.

Copied from closed: #12682

Fixes: flutter/flutter#191988

## Pre-Review Checklist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[image_picker] Android: uncaught NullPointerException in FileUtils.copy when openInputStream returns null (process crash)

1 participant