Skip to content

[image_picker] [Android] java.lang.SecurityException io.flutter.plugins.imagepicker.FileUtils.getPathFromUri #100025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
knnkrt opened this issue Mar 13, 2022 · 11 comments · Fixed by flutter/packages#4004
Labels
a: production Issues experienced in live production apps c: crash Stack traces logged to the console p: image_picker The Image Picker plugin. P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version

Comments

@knnkrt
Copy link

knnkrt commented Mar 13, 2022

I see an ANR on Google Play Store Console relating to

[Samsung Galaxy E5]
Android 5.1 (SDK 22)

java.lang.RuntimeException: 
  at android.app.ActivityThread.deliverResults (ActivityThread.java:4676)
  at android.app.ActivityThread.handleSendResult (ActivityThread.java:4719)
  at android.app.ActivityThread.access$1500 (ActivityThread.java:197)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1705)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:145)
  at android.app.ActivityThread.main (ActivityThread.java:6856)
  at java.lang.reflect.Method.invoke (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1404)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1199)
Caused by: java.lang.SecurityException: 
  at android.os.Parcel.readException (Parcel.java:1546)
  at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:185)
  at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel (DatabaseUtils.java:148)
  at android.content.ContentProviderProxy.openTypedAssetFile (ContentProviderNative.java:691)
  at android.content.ContentResolver.openTypedAssetFileDescriptor (ContentResolver.java:1131)
  at android.content.ContentResolver.openAssetFileDescriptor (ContentResolver.java:970)
  at android.content.ContentResolver.openInputStream (ContentResolver.java:695)
  at io.flutter.plugins.imagepicker.FileUtils.getPathFromUri (FileUtils.java)
  at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleChooseImageResult (ImagePickerDelegate.java)
  at io.flutter.plugins.imagepicker.ImagePickerDelegate.onActivityResult (ImagePickerDelegate.java)
  at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult (FlutterEngineConnectionRegistry.java)
  at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult (FlutterEngineConnectionRegistry.java)
  at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult (FlutterActivityAndFragmentDelegate.java)
  at io.flutter.embedding.android.FlutterActivity.onActivityResult (FlutterActivity.java)
  at android.app.Activity.dispatchActivityResult (Activity.java:6808)
  at android.app.ActivityThread.deliverResults (ActivityThread.java:4672)
  at android.app.ActivityThread.handleSendResult (ActivityThread.java:4719)
  at android.app.ActivityThread.access$1500 (ActivityThread.java:197)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1705)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:145)
  at android.app.ActivityThread.main (ActivityThread.java:6856)
  at java.lang.reflect.Method.invoke (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1404)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1199)
@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Mar 14, 2022
@danagbemava-nc
Copy link
Member

Hi @knnkrt, how many devices are experiencing this ANR, and what are their os versions?

What version of flutter was used to deploy the app and what version of image_picker is being used in the app?

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 14, 2022
@knnkrt
Copy link
Author

knnkrt commented Mar 14, 2022

Hi @danagbemava-nc ,

Only happened on [Samsung Galaxy E5] Android 5.1 (SDK 22) for 3 times.

Flutter 2.10.3 (stable and last version)
Dart >=2.16.1
image_picker: ^0.8.4+11 (stable and last version)

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 14, 2022
@danagbemava-nc
Copy link
Member

Hi @knnkrt, can you share the contents of your AndroidManifest.xml?

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 15, 2022
@knnkrt
Copy link
Author

knnkrt commented Mar 15, 2022

Hi @danagbemava-nc ,

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.XXXXXXXXXX.XXXXXXXXX">
    <uses-permission android:name="android.permission.INTERNET" />
   <application
        android:name="${applicationName}"
        android:label="XXXXXXX"
        android:icon="@mipmap/launcher_icon"
        android:allowBackup="false"
        android:usesCleartextTraffic="true">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize"
            android:exported="true">
            
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />
           
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.yalantis.ucrop.UCropActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
       
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/notification" />

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="general" />
        
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-XXXXXXXXXX~XXXXXXXXXXXXX"/>
    </application>
</manifest>

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 15, 2022
@danagbemava-nc
Copy link
Member

Hi @knnkrt, can you please provide the full output of flutter doctor -v?

Thank you

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 16, 2022
@knnkrt
Copy link
Author

knnkrt commented Mar 16, 2022

Hi @danagbemava-nc ,

[✓] Flutter (Channel stable, 2.10.3, on Microsoft Windows [Version 10.0.19044.1586], locale tr-TR)
    • Flutter version 2.10.3 at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (2 weeks ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\KENANKURT\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✗] Visual Studio - develop for Windows
    ✗ Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[✓] Android Studio (version 2021.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)

[✓] VS Code (version 1.65.2)
    • VS Code at C:\Users\KENANKURT\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.36.0

[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1586]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 99.0.4844.51
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 99.0.1150.30

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 16, 2022
@danagbemava-nc
Copy link
Member

Labeling for further investigation

@danagbemava-nc danagbemava-nc added c: crash Stack traces logged to the console platform-android Android applications specifically plugin p: image_picker The Image Picker plugin. a: production Issues experienced in live production apps and removed in triage Presently being triaged by the triage team labels Mar 17, 2022
@stuartmorgan-g stuartmorgan-g added the P2 Important issues not at the top of the work list label Mar 17, 2022
@miquelbeltran
Copy link
Member

I've seen the same in my Google Play developer console.

Affected device was Samsung Galaxy Note10 Lite with Android 12 (SDK 31).

java.lang.RuntimeException: 
  at android.app.ActivityThread.deliverResults (ActivityThread.java:5864)
  at android.app.ActivityThread.handleSendResult (ActivityThread.java:5903)
  at android.app.servertransaction.ActivityResultItem.execute (ActivityResultItem.java:54)
  at android.app.servertransaction.ActivityTransactionItem.execute (ActivityTransactionItem.java:45)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2438)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loopOnce (Looper.java:226)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8663)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:567)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)
Caused by: java.lang.SecurityException: 
  at android.os.Parcel.createExceptionOrNull (Parcel.java:2437)
  at android.os.Parcel.createException (Parcel.java:2421)
  at android.os.Parcel.readException (Parcel.java:2404)
  at android.database.DatabaseUtils.readExceptionFromParcel (DatabaseUtils.java:190)
  at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel (DatabaseUtils.java:153)
  at android.content.ContentProviderProxy.openTypedAssetFile (ContentProviderNative.java:780)
  at android.content.ContentResolver.openTypedAssetFileDescriptor (ContentResolver.java:2034)
  at android.content.ContentResolver.openAssetFileDescriptor (ContentResolver.java:1849)
  at android.content.ContentResolver.openInputStream (ContentResolver.java:1525)
  at io.flutter.plugins.imagepicker.c.c (Unknown Source:10)
  at io.flutter.plugins.imagepicker.e.s (Unknown Source:13)
  at io.flutter.plugins.imagepicker.e.a (Unknown Source:38)
  at io.flutter.embedding.engine.c$c.h (Unknown Source:25)
  at io.flutter.embedding.engine.c.a (Unknown Source:20)
  at io.flutter.embedding.android.e.o (Unknown Source:51)
  at io.flutter.embedding.android.d.onActivityResult (Unknown Source:10)
  at android.app.Activity.dispatchActivityResult (Activity.java:8659)
  at android.app.ActivityThread.deliverResults (ActivityThread.java:5857)

@JeroenWeener
Copy link

By the looks of it the SecurityException is thrown because the URI returned by the content provider cannot be accessed by the application. My guess is that a third-party gallery app was used that does not give a grant to read the URI.

To come up with a solution I have tried to reproduce the issue, but I was unable to. I tested the current newest version of the image picker (0.8.7+4) on

  • a Samsung Galaxy S6 running Android 7.0, picking from Google Photos, the Samsung Gallery app and Google Drive, only from internal storage.
  • a Samsung Galaxy Tab A running Android 10, picking from Google Photos, the Samsung Gallery app and the Samsung My Files app, both from internal storage and an external SD card.

@stuartmorgan-g
Copy link
Contributor

Absent a way to repro, I think the best option would be to wrap the failing call in a try/catch for SecurityException (with a comment referencing this issue) and ensure (via native unit tests) that we return null in that case instead of crashing. The selection still won't work obviously, but it won't bring the app down.

auto-submit bot pushed a commit to flutter/packages that referenced this issue May 19, 2023
Issue flutter/flutter#100025 mentions crashing of the image picker plugin due to a `SecurityException`. As research into the issue did not yield reproduction steps, we decided to surround the breaking method call with a `try/catch` block for now (see discussion in the issue). This PR implements just that. Instead of crashing on a `SecurityException`, the plugin will now return an image path of `null`.

This PR fixes flutter/flutter#100025.
@danagbemava-nc danagbemava-nc added the r: fixed Issue is closed as already fixed in a newer version label May 22, 2023
@github-actions
Copy link

github-actions bot commented Jun 5, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2023
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
nploi pushed a commit to nploi/packages that referenced this issue Jul 16, 2023
Issue flutter/flutter#100025 mentions crashing of the image picker plugin due to a `SecurityException`. As research into the issue did not yield reproduction steps, we decided to surround the breaking method call with a `try/catch` block for now (see discussion in the issue). This PR implements just that. Instead of crashing on a `SecurityException`, the plugin will now return an image path of `null`.

This PR fixes flutter/flutter#100025.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: production Issues experienced in live production apps c: crash Stack traces logged to the console p: image_picker The Image Picker plugin. P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants