Skip to content

Commit

Permalink
Canonicalize file path for insertion by legacy apps
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dipankarb1212 authored and thestinger committed Sep 6, 2023
1 parent c16e6e7 commit d577145
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/com/android/providers/media/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1324,9 +1324,17 @@ public static void computeValuesFromData(@NonNull ContentValues values, boolean
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));

Expand Down

0 comments on commit d577145

Please sign in to comment.