diff options
author | Dipankar Bhardwaj <dipankarb@google.com> | 2023-07-06 10:01:20 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-18 04:32:46 +0000 |
commit | af0f71ecb3cd76bfbcf01745d53a14f4f3658c15 (patch) | |
tree | 1430be7e08d9fd8564c44ffd03d833f805abdde5 | |
parent | dd6553e13c62632ec732df15c000331c0cf8a3cf (diff) | |
download | MediaProvider-af0f71ecb3cd76bfbcf01745d53a14f4f3658c15.tar.gz |
Canonicalize file path for insertion by legacy apps
Apps with legacy external storage can try to create entries in MP for
file paths in other apps external private directories by using a
non-canonical path in insertion calls.
Test: atest LegacyStorageHostTest#testInsertToOtherAppPrivateDirFails
Bug: 276898626
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:3c0f583f5dc3f4d395fa2423ab72dbd902c0c6c8)
Merged-In: If4c941c8156f19459b3ec6cbaf705824ecc2ba77
Change-Id: If4c941c8156f19459b3ec6cbaf705824ecc2ba77
-rw-r--r-- | src/com/android/providers/media/util/FileUtils.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/com/android/providers/media/util/FileUtils.java b/src/com/android/providers/media/util/FileUtils.java index d6296ae08..376cdf355 100644 --- a/src/com/android/providers/media/util/FileUtils.java +++ b/src/com/android/providers/media/util/FileUtils.java @@ -1327,9 +1327,17 @@ public class FileUtils { values.remove(MediaColumns.BUCKET_ID); values.remove(MediaColumns.BUCKET_DISPLAY_NAME); - final String data = values.getAsString(MediaColumns.DATA); + String data = values.getAsString(MediaColumns.DATA); if (TextUtils.isEmpty(data)) return; + try { + data = new File(data).getCanonicalPath(); + values.put(MediaColumns.DATA, data); + } catch (IOException e) { + throw new IllegalArgumentException( + String.format(Locale.ROOT, "Invalid file path:%s in request.", data)); + } + final File file = new File(data); final File fileLower = new File(data.toLowerCase(Locale.ROOT)); |