mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-07 23:38:40 +01:00
Improved stability of ShareProvider while querying file
Credit: Julien Thomas (https://twitter.com/julien_thomas) - Protektoid Project (https://protektoid.com)
This commit is contained in:
parent
b26c106781
commit
330b78b301
@ -69,11 +69,14 @@ public class ShareProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private File getFile(@NonNull Uri uri) throws FileNotFoundException {
|
private File getFile(@NonNull Uri uri) throws FileNotFoundException {
|
||||||
|
final Context context = getContext();
|
||||||
|
if (context == null) throw new IllegalStateException();
|
||||||
final String lastPathSegment = uri.getLastPathSegment();
|
final String lastPathSegment = uri.getLastPathSegment();
|
||||||
if (lastPathSegment == null) throw new FileNotFoundException(uri.toString());
|
if (lastPathSegment == null) throw new FileNotFoundException(uri.toString());
|
||||||
File filesDir = getFilesDir(getContext());
|
File filesDir = getFilesDir(context);
|
||||||
if (filesDir == null) throw new FileNotFoundException(uri.toString());
|
if (filesDir == null) throw new FileNotFoundException(uri.toString());
|
||||||
try {
|
try {
|
||||||
|
filesDir = filesDir.getCanonicalFile();
|
||||||
File file = new File(filesDir, lastPathSegment).getCanonicalFile();
|
File file = new File(filesDir, lastPathSegment).getCanonicalFile();
|
||||||
if (!FilesKt.startsWith(file, filesDir)) throw new SecurityException(uri.toString());
|
if (!FilesKt.startsWith(file, filesDir)) throw new SecurityException(uri.toString());
|
||||||
return file;
|
return file;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user