2026 年 11 月的 Android 安全公告里,评级最高的是 Framework 组件中的 CVE-2026-58868(内部编号 A-486464711):Critical 级远程代码执行,无需用户交互、无需额外执行权限,影响 Android 14、15、16、16 QPR2 和 17。
公告本身只给了一句话描述——FrameDecoder.cpp 的 onOutputReceived 中存在堆缓冲区溢出导致的越界写。这篇文章把对应的 AOSP 补丁拉下来,逐行看它到底改了什么、堵住了哪条路径。
补丁定位
公告为该 CVE 关联了两个 AOSP 提交:
platform/frameworks/av提交3419fbb558c4a5acc47270e2af821353824e9373platform/frameworks/av提交a8475208ed49b1eb5439af9703bcae0523f053c3
两个提交换的是同一处代码,分别落在不同分支上。提交信息:
FrameDecoder: Add checks for parameters from format.
Check before converting int32_t to size_t.
Bug: 498426107
Test: atest MediaMetadataRetrieverTest ImageReaderDecoderTest作者 Songyue Han,author 时间为 2026-05-20,合入时间 2026-08-19 / 08-20。提交说明里的 Bug: 498426107 是内部缺陷号,与公告里的 A-486464711 不是同一套编号,二者通过公告的链接对应。
修复前的代码
问题出在 media/libstagefright/FrameDecoder.cpp 的 MediaImageDecoder::onOutputReceived。这是图片解码(经 MediaCodec 解出图像帧后转 RGBA)的输出回调。修复前的关键片段:
status_t MediaImageDecoder::onOutputReceived(
uint8_t* frameData, sp<ABuffer> imgObj,
const sp<AMessage> &outputFormat, int64_t /*timeUs*/, bool *done) {
int32_t width, height, stride;
if (outputFormat->findInt32("width", &width) == false) {
ALOGE("...width is missing in outputFormat");
return ERROR_MALFORMED;
}
if (outputFormat->findInt32("height", &height) == false) {
ALOGE("...height is missing in outputFormat");
return ERROR_MALFORMED;
}
if (outputFormat->findInt32("stride", &stride) == false) {
ALOGE("...stride is missing in outputFormat");
return ERROR_MALFORMED;
}
int32_t crop_left, crop_top, crop_right, crop_bottom;
if (!outputFormat->findRect("crop", &crop_left, &crop_top,
&crop_right, &crop_bottom)) {
crop_left = crop_top = 0;
crop_right = width - 1;
crop_bottom = height - 1;
}
int32_t slice_height;
if (outputFormat->findInt32("slice-height", &slice_height) && slice_height > 0) {
height = slice_height;
}
int32_t crop_width, crop_height;
crop_width = crop_right - crop_left + 1;
crop_height = crop_bottom - crop_top + 1;
// ... 用 crop_width/crop_height 计算 dstLeft / dstTop / dstRight / dstBottom
// ... 最后传给 converter.convert(...)注意这里只做了"字段存不存在"的检查:width、height、stride 只要在 outputFormat 里能取到就继续往下走,没有任何范围校验。而这些值来自解码器输出的 AMessage,其内容最终由被解码的媒体数据决定。
补丁 diff
diff --git a/media/libstagefright/FrameDecoder.cpp b/media/libstagefright/FrameDecoder.cpp
@@ -1334,6 +1334,22 @@
height = slice_height;
}
+ if (crop_left < 0 || crop_top < 0 || crop_right < crop_left || crop_bottom < crop_top
+ || width <= 0 || height <= 0 || crop_bottom >= height || crop_right >= width
+ || stride < 0) {
+ ALOGE("Invalid crop, width and height in outputFormat. crop_left: %d, crop_right: %d,"
+ " crop_top: %d, crop_bottom: %d, width: %d, height: %d", crop_left, crop_right,
+ crop_top, crop_bottom, width, height);
+ return ERROR_MALFORMED;
+ }
+ if (stride < 0 || (stride & 1) != 0) {
+ // stride could be zero and must be even.
+ // If the client set the stride to zero,
+ // the BitmapParams constructor calculates it based on width and bpp.
+ ALOGE("Invalid stride in outputFormat: %d", stride);
+ return ERROR_MALFORMED;
+ }
+
int32_t crop_width, crop_height;
crop_width = crop_right - crop_left + 1;
crop_height = crop_bottom - crop_top + 1;逐条看校验条件
补丁加了六类判断,全部在计算 crop_width 之前,任意一条不满足就返回 ERROR_MALFORMED:
| 校验 | 拦截的情况 |
|---|---|
crop_left 小于 0,或 crop_top 小于 0 | 裁剪原点为负 |
crop_right 小于 crop_left,或 crop_bottom 小于 crop_top | 裁剪右/下边界小于左/上边界,面积反向 |
width 或 height 小于等于 0 | 宽或高非正 |
crop_bottom 大于等于 height,或 crop_right 大于等于 width | 裁剪区域超出图像边界 |
stride 小于 0 | 行跨距为负 |
stride 为奇数 | 行跨距非偶数 |
关于最后一条,注释写得很明确:stride 允许为 0,此时由下游 BitmapParams 按 width 和 bpp 自行计算;非零时必须为偶数。这个约束来自 YUV 平面按 2 字节对齐的寻址方式——行跨距为奇数会让色度平面的偏移落错位置。
为什么"未校验"会变成越界写
关键在调用链的类型转换。onOutputReceived 拿到的 width/height/stride/crop_* 都是 int32_t,但传给 ColorConverter::convert 时,形参是 size_t:
status_t ColorConverter::convert(
const void *srcBits,
size_t srcWidth, size_t srcHeight, size_t srcStride,
size_t srcCropLeft, size_t srcCropTop,
size_t srcCropRight, size_t srcCropBottom,
void *dstBits, ...);提交说明那句"Check before converting int32_t to size_t"说的就是这里:一个负的 int32_t(例如 crop_left = -1)转换成 size_t 后会变成一个接近 SIZE_MAX 的巨大数值,后续所有基于它的加减都在无符号域里回绕。
ColorConverter::BitmapParams 里的面积计算同样在 size_t 上做:
size_t ColorConverter::BitmapParams::cropWidth() const {
return mCropRight - mCropLeft + 1;
}isValid() 只检查两件事——stride 为偶数、且 stride >= mBpp * cropWidth()——它无法覆盖"裁剪区域超出图像实际尺寸"这类错误。
回到 onOutputReceived,越界写的位置也很具体:目标偏移由裁剪尺寸推导,
dstLeft = mTilesDecoded % mGridCols * crop_width;
dstTop = mTilesDecoded / mGridCols * crop_height;crop_width / crop_height 一旦被畸形参数放大或回绕,dstLeft、dstTop 就会指向目标帧缓冲区之外,随后颜色转换按行写入时落笔越界。目标缓冲区是按 mWidth × mHeight 分配的,写入位置的正确性完全依赖源参数可信——这正是补丁要补掉的前提。
因此这条漏洞的本质不是"解码器算错了",而是信任了来自码流一侧的格式参数:把一个外部可控的 int32_t 直接当成 size_t 使用,边界检查在下游已经来不及了。
攻击面与影响
代码位于图片解码路径(MediaImageDecoder),对应的是应用或系统组件把一张图片交给 MediaCodec 解码、再转成 RGBA 的场景:缩略图生成、MediaMetadataRetriever、ImageDecoder、图库与媒体扫描等。公告将其定为"无需用户交互",与这类"内容到达即解码"的路径一致。
需要说明的是,公告与 CVE 记录都没有写明攻击者具体通过哪条路径触达该函数,Critical 评级的前提是"平台内置防护被关闭或绕过"。补丁能确认的是:畸形格式参数不会再流进颜色转换。
同一批里还有几个值得一起看:
- CVE-2026-58876、CVE-2026-58936:System 组件的 Critical 级 RCE
- CVE-2026-58882:WAP Push(短信)
decodeWapPdu的远程 DoS,一条畸形短信即可让com.android.phone崩溃并中断当前通话,包括紧急呼叫 - 内核 6 个 Critical(2 个在蓝牙),MediaTek Modem 多个 Critical 越界写
处置
- 补丁级别
2026-11-01及以后包含本 CVE 的修复;2026-11-05覆盖整份公告 - 公告没有提供临时缓解手段,只能等待 OEM / 运营商推送
- 自查:
adb shell getprop ro.build.version.security_patch,或在 设置 → 关于手机 → Android 版本 中查看安全更新日期 - 回归测试可直接用提交里写的用例:
atest MediaMetadataRetrieverTest ImageReaderDecoderTest
对做系统定制与设备交付的项目,建议把 2026-11-05 写进验收基线,交付前逐台核验补丁级别,而不是只看厂商公告有没有提到这个 CVE。
参考
- Android Security Bulletin — November 2026:https://source.android.com/docs/security/bulletin/2026/2026-11-01
- 修复提交 1:https://android.googlesource.com/platform/frameworks/av/+/3419fbb558c4a5acc47270e2af821353824e9373
- 修复提交 2:https://android.googlesource.com/platform/frameworks/av/+/a8475208ed49b1eb5439af9703bcae0523f053c3
- CVE-2026-58868 记录:https://www.cve.org/CVERecord?id=CVE-2026-58868
评论
发表评论