CVE-2026-59022 AI-generated analysis
platform/packages/providers/MediaProvider, MediaProvider query path (owner_package_name redaction)
Replaces the exact-string match used to find and redact the owner_package_name column in MediaStore query projections with word-boundary regex detection and in-expression substitution, so the CASE WHEN redaction is applied even when the column appears inside aggregates, aliases, DISTINCT/ALL prefixes or repeated elements.
Root cause
In MediaProvider.java, projectionNeedsOwnerPackageFiltering() decided whether redaction was required with Arrays.asList(proj).contains(MediaColumns.OWNER_PACKAGE_NAME). prepareSubstitution() only rewrote a projection element when it exactly matched "owner_package_name" (case-insensitive). Any element that referenced the column in another form (for example inside an aggregate such as MAX(), with an alias, or after DISTINCT) went to SQLiteQueryBuilder unchanged. As a result, callers could get the raw owner_package_name value where they should have received NULL for packages they cannot query. The substitution string also ended in a hard-coded "AS owner_package_name", so it could only replace a bare column and could not be embedded in an expression.
How the fix works
- MediaProvider.java:projectionNeedsOwnerPackageFiltering: for a non-null projection, each element is passed through splitProjection() to remove a trailing alias, then checked with containsWord(expr, OWNER_PACKAGE_NAME). This is a case-insensitive regex search bounded by \b, and it replaces the exact list membership test. The null-projection branch (projection map contains the column) is unchanged.
- MediaProvider.java:constructOwnerPackageNameProjection is renamed to constructOwnerPackageNameSubstitution. It now returns only "CASE WHEN owner_package_name IN ('a','b') THEN owner_package_name ELSE NULL END" with no "AS owner_package_name" suffix, so it can replace every occurrence of the column inside any expression. The Log.d of the constructed string is removed.
- MediaProvider.java:prepareSubstitution handles each element as follows. Null elements are kept. A leading DISTINCT or ALL keyword is split off as a prefix. splitProjection() separates the expression from the alias. If containsWord() finds the column, FILTER_COLUMN_PATTERNS.get(OWNER_PACKAGE_NAME).matcher(expr).replaceAll(substitution) rewrites every occurrence. The caller's alias is kept if present. If the expression was the bare column, "AS owner_package_name" is added back. Otherwise the rewritten expression is aliased with the original expression text as a double-quoted identifier, with inner double quotes doubled. As before, the rebuilt element is added to the projection allowlist via Pattern.quote.
- MediaProvider.java adds two helpers. The private static containsWord() does a lowercase substring fast path, then looks up a word-boundary Pattern in FILTER_COLUMN_PATTERNS or compiles one on the fly. The private instance method splitProjection() uses ALIAS_PATTERN " (?:as )?([_a-z0-9]+)$" to split off a trailing alias. On Android 15, this commit introduces the FILTER_COLUMN_PATTERNS map (containing OWNER_PACKAGE_NAME) and ALIAS_PATTERN. The 16/17 diffs only add an OWNER_PACKAGE_NAME entry to an existing FILTER_COLUMN_PATTERNS map, which already lists LATITUDE, LONGITUDE, OEM_METADATA and, on 17, _SPECIAL_FORMAT.
- Android 15 only, MediaProvider.java:queryInternal: calls qb.enforceStrictColumns(projection) and projection = maybeReplaceNullProjection(projection, qb) before the shouldFilterOwnerPackageNameFlag()/shouldFilterOwnerPackageNameInProjection() check. This means strict column validation and null/wildcard expansion now happen before the redaction decision. To allow this, SQLiteQueryBuilder.java:enforceStrictColumns(String[]) changes from private to public.
- Android 15 only, MediaProvider.java:maybeReplaceNullProjection: the existing null-projection branch now returns early. After it, the method expands explicit "*" elements into qb.getAllColumnsFromProjectionMap() for callers with targetSdkVersion < Q, and calls qb.setStrictColumns(false) when a wildcard was expanded.
Completeness
- Covers owner_package_name references in projection elements in any letter case, inside function calls or operators, after a DISTINCT/ALL prefix, with a trailing alias (with or without AS), and when repeated within one element or across elements, because replaceAll rewrites every word-bounded match.
- Only the projection is sanitized. The diff does not touch selection, selectionArgs, sort order, GROUP BY or HAVING clauses passed to qb.query(). The material does not show whether other code restricts owner_package_name in those clauses.
- ALIAS_PATTERN only recognizes an alias of the form [_a-z0-9]+ at the end of the element, preceded by a space. Elements with other alias forms are treated entirely as the expression. The column is still substituted inside them, and the element gets an additional generated quoted alias.
- The redaction is still gated by shouldFilterOwnerPackageNameFlag() and shouldFilterOwnerPackageNameInProjection(), which are unchanged. The fix does not change which callers are redacted, only how the projection is rewritten for them.
- The null-projection branch of projectionNeedsOwnerPackageFiltering is unchanged. On Android 15, queryInternal now calls maybeReplaceNullProjection before the shouldFilterOwnerPackageNameInProjection() check, so a null projection is expanded before that check.
Behavior changes
- For redacted callers, any projection expression that mentions owner_package_name is rewritten to a CASE WHEN expression. Output column names are kept when the caller supplied an alias. For non-bare expressions without an alias, the column is now named with the original expression text as a quoted identifier.
- Android 15: qb.enforceStrictColumns(projection) now runs in queryInternal before the owner_package_name filter, so invalid columns are rejected earlier in the query path. maybeReplaceNullProjection is also applied before the filter.
- Android 15: for callers targeting SDK < Q, a literal "*" projection element is expanded to all projection-map columns, and strict column checking is turned off for that query.
- The debug log of the constructed substitution string is removed. The existing Log.i of the filtered projection remains.
Per major
- Android 14: Not affected per the bulletin. At android-security-14.0.0_r31 only 1/8 lines of the patched region are present. The material does not show the state of the redaction code there.
- Android 15: Adapted fix (28449503182b, android-security-15.0.0_r19). Same core rewrite of projectionNeedsOwnerPackageFiltering, prepareSubstitution and constructOwnerPackageNameSubstitution. In addition, this commit adds the FILTER_COLUMN_PATTERNS map, ALIAS_PATTERN, the containsWord and splitProjection helpers, the early enforceStrictColumns/maybeReplaceNullProjection calls in queryInternal, wildcard expansion for targetSdk < Q, and makes SQLiteQueryBuilder.enforceStrictColumns public.
- Android 16: Adapted fix (d2d83c4061f9, android-security-16.0.0_r10). Same core rewrite. The diff adds only the OWNER_PACKAGE_NAME entry to the existing FILTER_COLUMN_PATTERNS map and uses containsWord, splitProjection and ALIAS_PATTERN without adding them, which suggests they already exist. The diff shown touches only MediaProvider.java and has no queryInternal changes.
- Android 17: Adapted fix (7e2907ad40f0, android-security-17.0.0_r3). Same content as the 16 change, with the OWNER_PACKAGE_NAME map entry inserted before the existing _SPECIAL_FORMAT entry.
Unknowns
- Which concrete projection forms the reporter used. The commit message cites MAX() and repeated columns but does not detail the repeated-columns mechanism.
- Whether owner_package_name references in selection, sort order or GROUP BY clauses are restricted elsewhere. This commit does not touch them.
- The exact logic of shouldFilterOwnerPackageNameFlag() and shouldFilterOwnerPackageNameInProjection(), including whether the latter calls projectionNeedsOwnerPackageFiltering. Beyond the commit message saying redaction applies to apps targeting SDK >= U, this is not shown.
- Why the Android 15 variant also moves enforceStrictColumns/maybeReplaceNullProjection into queryInternal and adds wildcard expansion while 16/17 do not. These may already be present on 16/17, but the material does not show it.
- How SQL execution handles elements with alias forms that ALIAS_PATTERN does not recognize, after a generated alias is appended.
- Whether the Android 15 variant needs new imports (for example java.util.regex.Matcher or java.util.Map). Import changes are not shown in the diff.