Skip to content
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

SecurityException when loading thumbnail on some devices #3504

Closed
dbarwacz opened this issue Jan 28, 2019 · 11 comments
Closed

SecurityException when loading thumbnail on some devices #3504

dbarwacz opened this issue Jan 28, 2019 · 11 comments
Labels

Comments

@dbarwacz
Copy link

dbarwacz commented Jan 28, 2019

Glide: 4.8.0
Integration: irrelevant (local image)
Device: some samsungs

We use glide to load preview from image selected using system picker. On some samsungs, it causes SecurityException, as apparently app does not have access to thumbnail of an image.
Actual resource uri is accessible, as we are still able to upload it.

We've migrated from picasso recently. We've had same issues with Picasso. Glide seemed to work ok, but apparently not on all devices.

How can we skip request for thumbnail?
Is it configurable?

@joimxjtuse
Copy link

Show exception log may help to solve the problem.

@dbarwacz
Copy link
Author

Sure, here it is:

E/DatabaseUtils: Writing exception to parcel
    java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/thumbnails from pid=16105, uid=10259 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
        at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:641)
        at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:507)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:218)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:102)
        at android.os.Binder.execTransact(Binder.java:682)
2019-01-28 11:37:28.453 16105-21839/com.hidden.app E/LocalConsoleLoggingManager: Not uploading exceptions encountered in debug builds:
    java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/thumbnails from pid=16105, uid=10259 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
        at android.os.Parcel.readException(Parcel.java:1967)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
        at android.content.ContentProviderProxy.query(ContentProviderNative.java:418)
        at android.content.ContentResolver.query(ContentResolver.java:760)
        at android.content.ContentResolver.query(ContentResolver.java:710)
        at android.content.ContentResolver.query(ContentResolver.java:668)
        at com.bumptech.glide.load.data.mediastore.ThumbFetcher$ImageThumbnailQuery.query(ThumbFetcher.java:158)
        at com.bumptech.glide.load.data.mediastore.ThumbnailStreamOpener.getPath(ThumbnailStreamOpener.java:93)
        at com.bumptech.glide.load.data.mediastore.ThumbnailStreamOpener.open(ThumbnailStreamOpener.java:71)
        at com.bumptech.glide.load.data.mediastore.ThumbFetcher.openThumbInputStream(ThumbFetcher.java:71)
        at com.bumptech.glide.load.data.mediastore.ThumbFetcher.loadData(ThumbFetcher.java:58)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:302)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:272)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:233)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)

@stale
Copy link

stale bot commented Feb 7, 2019

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

@stale stale bot added the stale label Feb 7, 2019
@krsoaiheim
Copy link

I have the same problem

@stale stale bot removed the stale label Feb 12, 2019
@dbarwacz
Copy link
Author

dbarwacz commented Feb 12, 2019 via email

@stale
Copy link

stale bot commented Feb 19, 2019

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

@stale stale bot added the stale label Feb 19, 2019
@sjudd
Copy link
Collaborator

sjudd commented Feb 19, 2019

You'll need to get the read storage permission for your app to load images from media store. How would you like Glide to help you here?

@stale stale bot removed the stale label Feb 19, 2019
@dbarwacz
Copy link
Author

That's not true @sjudd because I'm granted temporary access by picker activity ('We use glide to load preview from image selected using system picker') which is confirmed as I can access resource directly ('Actual resource uri is accessible, as we are still able to upload it'). Only glide attempts to load thumbnail that apparently has system-specific bugs.

@stale
Copy link

stale bot commented Feb 27, 2019

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

@stale stale bot added the stale label Feb 27, 2019
@sjudd sjudd added bug and removed stale labels Feb 28, 2019
@sjudd
Copy link
Collaborator

sjudd commented Feb 28, 2019

Got it thanks for clarifying.

So you have Uri permissions for content://media/external/images/media/ but accessing the equivalent thumbnail with content://media/external/images/thumbnails/ fails.

@sjudd
Copy link
Collaborator

sjudd commented Feb 28, 2019

Internal issue is b/126712454, but we can work around this in Glide without a framework change.

sjudd added a commit to sjudd/glide that referenced this issue Mar 5, 2019
A Uri permission grant for a MediaStore Uri will only grant access to the main Uri, not the thumbnail Uri. Applications that have only Uri permissions and not the storage runtime permissions will receive a SecurityException when they try to open the corresponding thumbnail. 

Prior to this change, the thumbnail exception would cause the entire
request to fail. After this change only the thumbnail portion of the request will fail so the image may still be loaded via the original MediaStore Uri. 

Fixes bumptech#3504.
@sjudd sjudd closed this as completed in 9c48b48 Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants