CVE-2026-58868 AI-generated analysis
platform/frameworks/av, libstagefright FrameDecoder (MediaImageDecoder; commit tests reference MediaMetadataRetrieverTest and ImageReaderDecoderTest)
Adds range and consistency validation of the width, height, stride and crop rectangle read from the codec output format in MediaImageDecoder::onOutputReceived (media/libstagefright/FrameDecoder.cpp), returning ERROR_MALFORMED instead of using unchecked int32_t values (the commit message: 'Check before converting int32_t to size_t').
Root cause
MediaImageDecoder::onOutputReceived reads "width", "height", "color-format", "stride", "crop" and "slice-height" from outputFormat and, after optionally replacing height with slice-height, computes crop dimensions as crop_right - crop_left + 1 and crop_bottom - crop_top + 1, which are used for frame allocation (allocVideoFrame in the code context). No check ensured that crop coordinates were non-negative, that right >= left and bottom >= top, that the crop rectangle lay inside width/height, that width/height were positive, or that stride was non-negative and even. The commit message describes the problem as converting int32_t to size_t without a prior check.
How the fix works
- media/libstagefright/FrameDecoder.cpp : MediaImageDecoder::onOutputReceived: immediately after the slice-height adjustment and before crop_width/crop_height are computed, a new check rejects the output with ALOGE + return ERROR_MALFORMED when crop_left < 0, crop_top < 0, crop_right < crop_left, crop_bottom < crop_top, width <= 0, height <= 0, crop_bottom >= height, crop_right >= width, or stride < 0.
- Same function: a second check rejects stride < 0 (redundant with the first) or odd stride ((stride & 1) != 0); stride 0 is explicitly allowed, with the comment that the BitmapParams constructor derives it from width and bpp when zero.
- Because height may have been overwritten by slice-height before the check, the crop_bottom >= height comparison is made against the effective (slice) height.
- Single commit, pure insertion of 16 lines; no other call sites or helper functions are changed.
Completeness
- Covers: sign and ordering of crop coordinates, crop within width/height, positive width/height, non-negative and even stride, all at the single point where these values enter MediaImageDecoder::onOutputReceived.
- Does not check stride against width (a stride smaller than width times bytes-per-pixel is still accepted), and does not check for arithmetic overflow of products such as stride * height; whether downstream code handles those is not shown in the material.
- slice-height is only required to be > 0 to replace height; no relation between slice-height and the original height is enforced, although the crop check is applied against the replaced value.
- Only MediaImageDecoder::onOutputReceived is modified; the material does not show whether other onOutputReceived implementations in FrameDecoder.cpp have equivalent validation.
- The stride < 0 condition appears in both checks; harmless redundancy.
Behavior changes
- onOutputReceived now returns ERROR_MALFORMED (with an ALOGE line) for output formats with negative, inverted or out-of-range crop rectangles, non-positive width/height, or negative stride; previously such outputs were processed.
- Odd stride values from the output format are now rejected (stride must be even); stride 0 remains accepted.
- Image extraction through this decoder fails for such inputs instead of producing a frame.
Per major
- Android 14: same fix: commit ddb110eb65fd in android-security-14.0.0_r31, linked by Change-Id Ie4fec9bc89d332cd56f5818a86cf83ee282a19b2; identical 16-line insertion at hunk @@ -1004; 4/4 lines of the patched region present.
- Android 15: same fix: commit 23b6504a9d26 in android-security-15.0.0_r19; identical diff at hunk @@ -1033; 4/4 lines present.
- Android 16: same fix: commit 3419fbb558c4 in android-security-16.0.0_r10; identical diff at hunk @@ -1334; 4/4 lines present.
- Android 17: same fix: commit a8475208ed49 in android-security-17.0.0_r3; identical diff at hunk @@ -1352; 4/4 lines present.
Unknowns
- The exact downstream consumer where the int32_t to size_t conversion causes the memory-safety problem (allocVideoFrame, BitmapParams, or a copy/convert step) is not shown in the material.
- The supplied 'code around the fix' context (lines 631-688, inline crop arithmetic in allocVideoFrame call) does not match the hunk location (line 1004, crop_width/crop_height locals) of the Android 14 fix commit, so the precise pre-fix code at android-security-14.0.0_r31 is not fully confirmed.
- Whether other onOutputReceived implementations or other consumers of codec output formats in FrameDecoder.cpp perform equivalent validation is not shown.
- Which specific input (file format, codec) triggers the invalid output format values, and whether the MediaMetadataRetriever path is the only entry point, is not shown.