CVE-2026-58821 AI-generated analysis
platform/packages/providers/MediaProvider, photo picker v2 search request database (SearchRequestDatabaseUtil)
Replaces String.format()-built WHERE clause literals in the photo picker search request ID lookup (SearchRequestDatabaseUtil) with "?" placeholders and a selectionArgs array passed to SQLiteDatabase.rawQuery, so search text, mime types, media set id, authority and suggestion type are bound as parameters instead of being spliced into SQL.
Root cause
In SearchRequestDatabaseUtil.java, the private helper addWhereClause built each equality predicate with String.format(Locale.ROOT, " %s = '%s' ", columnName, value) and appended it via queryBuilder.appendWhereStandalone. addSearchRequestIDWhereClause called this helper for MIME_TYPES, SEARCH_TEXT, MEDIA_SET_ID, SUGGESTION_AUTHORITY and SUGGESTION_TYPE, taking the values from the SearchRequest object. The search request ID lookup (getSearchRequestID) then executed the result with database.rawQuery(queryBuilder.buildQuery(), null). Because the values (notably the search text) were placed inside single quotes in the SQL string with no escaping, a value containing a quote character could alter the structure of the query run against the picker database.
How the fix works
- SearchRequestDatabaseUtil.java:addWhereClause now takes an additional @NonNull List<String> selectionArgs. It emits String.format(Locale.ROOT, " %s = ? ", columnName), so only the column name is formatted, and appends getValueOrPlaceholder(value) to selectionArgs, which keeps the null-to-placeholder behaviour.
- SearchRequestDatabaseUtil.java:addSearchRequestIDWhereClause gains a selectionArgs parameter and forwards it to all five addWhereClause calls (MIME_TYPES, SEARCH_TEXT, MEDIA_SET_ID, SUGGESTION_AUTHORITY, SUGGESTION_TYPE), so the bound argument order matches the placeholder order.
- SearchRequestDatabaseUtil.java (search request ID lookup, getSearchRequestID) creates a new ArrayList<String> selectionArgs, passes it to addSearchRequestIDWhereClause, and calls database.rawQuery(queryBuilder.buildQuery(), selectionArgs.toArray(new String[0])) instead of passing null selectionArgs.
- SearchRequestDatabaseUtilTest.java adds testMaliciousSearchTextIsTreatedAsRegularSearchQuery. It saves a SearchTextRequest whose search text contains a quote and a DELETE statement, looks it up with getSearchRequestID, fetches it with getSearchRequestDetails, and asserts the text round-trips unchanged.
Completeness
- Covers all five predicates generated by addSearchRequestIDWhereClause, which is the only caller of addWhereClause shown in the diff. The rawQuery in the search request ID lookup is the only query site changed.
- addSearchRequestDetailsWhereClause (visible in the diff context immediately after addSearchRequestIDWhereClause) is not modified. The material does not show its body, so whether it formats string values the same way is unknown.
- updateResumeKey (code context) still builds its where clause with String.format, but the only interpolated value is the int searchRequestId via %d, which is not a string injection vector.
- The fix does not change how search text is validated at the entry point. It only makes the database lookup treat the text as data.
Behavior changes
- Search request values containing SQL metacharacters (quotes, semicolons, comment markers) are now matched literally. The new test shows such a request is found and round-trips unchanged.
- The query text sent to SQLite changes from inline literals to bound parameters. Only private helper signatures change.
Per major
- Android 14: not affected per bulletin; SearchRequestDatabaseUtil.java and its test are absent at android-security-14.0.0_r31 (code absent)
- Android 15: not affected per bulletin; patched files absent at android-security-15.0.0_r19 (code absent)
- Android 16: same fix: commit f108d16cda10 in android-security-16.0.0_r8, a RESTRICT AUTOMERGE cherry-pick of db4125270edb (Change-Id Iea199bea9111705d8d4131e82bc726db49851232); 7/8 patched-region lines present at android-security-16.0.0_r10
- Android 17: same fix: commit 8dc44d72ec89 in android-security-17.0.0_r1 with the same diff (same file index hashes 1c8781671..63fb2d49d); 7/8 patched-region lines present at android-security-17.0.0_r3
Unknowns
- The body of addSearchRequestDetailsWhereClause and whether it uses the same String.format literal pattern.
- The entry point through which an untrusted app or user controls the search text that reaches the search request ID lookup, and the concrete information disclosed (the bulletin only classifies it as ID, High).
- Which line of the patched region is missing at the latest 16 and 17 security tags (7/8 reported) and whether it is a whitespace or test-only difference.
- Whether the fix is also delivered through other channels, such as a module update.