CVE-2026-58853 AI-generated analysis
platform/packages/services/BuiltInPrintService, libwfds JNI IPP helper (jni/ipphelper/ipphelper.c)
Adds bounds checks in jni/ipphelper/ipphelper.c (the media-supported loop in parse_getMediaSupported and the helper addMediaIfNotDuplicate) so that media entries parsed from a printer's Get-Printer-Attributes response can no longer be written past the PAGE_STATUS_MAX-sized arrays in media_supported_t.
Root cause
parse_getMediaSupported in jni/ipphelper/ipphelper.c fills media_supported->media_size[] and media_supported->idxKeywordTranTable[] using a running index, sizes_idx. These are fixed-size arrays of PAGE_STATUS_MAX entries (200 per the test comment). The media-supported loop went through every value up to ippGetCount(attrptr) with no upper bound on sizes_idx. The helper addMediaIfNotDuplicate wrote media_size[*sizes_idx] and idxKeywordTranTable[*sizes_idx] and incremented *sizes_idx without checking it against PAGE_STATUS_MAX. As a result, a Get-Printer-Attributes response with more than 200 recognized media values in media-supported caused writes past the end of the arrays. The added test says this was a stack buffer overflow / crash before the fix.
How the fix works
- jni/ipphelper/ipphelper.c:addMediaIfNotDuplicate: adds an early return, `if (sizes_idx == NULL || *sizes_idx >= PAGE_STATUS_MAX) return;`, before any read of idxKeywordTranTable or write to media_size/idxKeywordTranTable. Every caller of this helper is now capped at PAGE_STATUS_MAX entries. The material does not show which code paths call it.
- jni/ipphelper/ipphelper.c:parse_getMediaSupported: the media-supported loop condition changes from `i < ippGetCount(attrptr)` to `i < ippGetCount(attrptr) && sizes_idx < PAGE_STATUS_MAX`. The loop now stops once the array is full instead of continuing to write.
- jni/ipphelper/ipphelper_test.cpp (new) and jni/Android.bp: add the cc_test target libwfds_ipphelper_test. It builds ipphelper.c, ipp_print.c and ippstatus_capabilities.c directly, passes parse_getMediaSupported a media-supported attribute with 1000 valid keywords, and asserts that exactly PAGE_STATUS_MAX entries are written and that a local canary variable is intact. Android.bp also adds default_team to the package block (not on 14).
Completeness
- Covers both write sites visible in the material: the direct media-supported loop in parse_getMediaSupported and the shared helper addMediaIfNotDuplicate, which guards all its callers.
- The loop-bound check on media-supported is only enough if the loop body writes at most once per iteration. The diff does not show the body, but the new test (1000 values, exactly 200 written) exercises this path.
- The media-col-ready loop (shown in the index excerpt) still iterates up to the full ippGetCount. It is protected only to the extent that its writes go through addMediaIfNotDuplicate. The material does not show whether addRollSupportedSizes or other code writes into media_supported or capabilities arrays without going through the helper. One example is the numSupportedMediaReadySizes counter asserted in the 16/17 test.
- Excess entries are silently dropped; no logging or error is added.
Behavior changes
- At most PAGE_STATUS_MAX (200) media entries are recorded in media_supported_t; any further values are ignored. The media-supported path does not de-duplicate in C, so repeated values count toward the cap.
- addMediaIfNotDuplicate now returns without doing anything when sizes_idx is NULL or already at PAGE_STATUS_MAX.
- New unit test target libwfds_ipphelper_test; new default_team in jni/Android.bp (15/16/17).
Per major
- Android 14: same fix: 2ec9f87450f5 in android-security-14.0.0_r29. The ipphelper.c hunks are identical (lines 969/1098). Android.bp lacks the default_team line and the aconfig deps. 8/8 patched lines present at android-security-14.0.0_r31.
- Android 15: same fix: b82964c3f229 in android-security-15.0.0_r17 (the reference diff). 8/8 patched lines present at android-security-15.0.0_r19.
- Android 16: same fix: 883f3a1848ea in android-security-16.0.0_r8. The ipphelper.c hunks are at lines 970/1105. The cc_test also links bips_aconfig_flags_cc_lib and libaconfig_storage_read_api_cc, and the test adds EXPECT_EQ(capabilities_.numSupportedMediaReadySizes, 0). 8/8 lines present at android-security-16.0.0_r10.
- Android 17: same fix: c343ebe454ba in android-security-17.0.0_r1. The ipphelper.c hunks are at lines 1021/1154, with the same Android.bp/test variant as 16. 8/8 lines present at android-security-17.0.0_r3.
Unknowns
- The material does not show the body of the media-supported loop or the callers of addMediaIfNotDuplicate (for example the media-col-ready and media-ready paths, or addRollSupportedSizes). So it cannot confirm that no other write to media_supported or capabilities arrays bypasses the new checks.
- Whether media_supported_t lives on the stack or the heap in the production caller. The test places it on the stack and calls the result a stack buffer overflow.
- What the Cherrypick-From internal commits 852c02f8 and ee22adf7 each contained.