Skip to content

Commit b4b8478

Browse files
committed
Handle _ and % in paths
When doing a "like" match on a path, add a second non-like constraint so that sqlite wildcard characters don't match arbitrary other characters. b/6501408 Change-Id: I21f9b1c2d8e7c7ef27c0ad5fe24c3e01cd67fb61
1 parent 956f28e commit b4b8478

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

media/java/android/media/MediaScanner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,9 @@ FileEntry makeEntryFor(String path) {
14441444
String where;
14451445
String[] selectionArgs;
14461446
if (mCaseInsensitivePaths) {
1447-
where = Files.FileColumns.DATA + " LIKE ?";
1447+
// the 'like' makes it use the index, the 'lower()' makes it correct
1448+
// when the path contains sqlite wildcard characters
1449+
where = "_data LIKE ?1 AND lower(_data)=lower(?1)";
14481450
selectionArgs = new String[] { path };
14491451
} else {
14501452
where = Files.FileColumns.DATA + "=?";

media/java/android/mtp/MtpDatabase.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,8 +932,11 @@ private int deleteFile(int handle) {
932932
if (format == MtpConstants.FORMAT_ASSOCIATION) {
933933
// recursive case - delete all children first
934934
Uri uri = Files.getMtpObjectsUri(mVolumeName);
935-
int count = mMediaProvider.delete(uri, "_data LIKE ?",
936-
new String[] { path + "/%"});
935+
int count = mMediaProvider.delete(uri,
936+
// the 'like' makes it use the index, the 'lower()' makes it correct
937+
// when the path contains sqlite wildcard characters
938+
"_data LIKE ? AND lower(substr(_data,?))=lower(?)",
939+
new String[] { path + "/%", "" + path.length() + 1, path + "/"});
937940
}
938941

939942
Uri uri = Files.getMtpObjectsUri(mVolumeName, handle);

0 commit comments

Comments
 (0)