Skip to content

🛡️ Sentinel: [MEDIUM] Fix MediaFormat API compatibility causing DoS - #69

Open
Shangjin-Xiao wants to merge 1 commit into
mainfrom
sentinel-fix-mediaformat-dos-9835182981235804504
Open

🛡️ Sentinel: [MEDIUM] Fix MediaFormat API compatibility causing DoS#69
Shangjin-Xiao wants to merge 1 commit into
mainfrom
sentinel-fix-mediaformat-dos-9835182981235804504

Conversation

@Shangjin-Xiao

@Shangjin-Xiao Shangjin-Xiao commented Aug 25, 2026

Copy link
Copy Markdown
Owner

🚨 严重程度

MEDIUM

💡 漏洞

代码中使用了 MediaFormat.containsKey(),该方法在 Android API 29 中才被引入,而项目的 minSdk 是 26。当应用程序在较低版本的 Android 系统上解析不受信任或格式错误的媒体文件时,如果缺少某些键值,执行到该方法会抛出 NoSuchMethodError

🎯 影响

由于无法捕获这种 LinkageError 级别的异常,应用程序会直接崩溃。恶意构造的媒体文件可以利用这一点在本地引发拒绝服务(DoS)攻击,或者让老设备用户在正常导出/提取帧时频繁遭遇应用闪退。

🛠️ 修复

  • 移除了所有在 FrameExporterColorSpaceDetectorMetadataExtractor 中对 MediaFormat.containsKey() 的调用。
  • 使用 Kotlin 的 runCatching { format.get*(key) }.getOrNull() 范式进行替换。这不仅安全地尝试获取所需的元数据,还通过内部吸收异常防止了应用崩溃。
  • 同步更新了 ColorSpaceDetectorTest.kt 中的 mock 行为,确保单元测试通过。
  • 修复过程严格限定在了 MediaFormat 范围内,未影响其他正常使用 containsKey 的集合(如 MapConcurrentHashMap 缓存)。

✅ 验证

  • 成功编译了应用 (./gradlew :app:assembleDebug)。
  • 核心媒体模块单元测试全部通过 (./gradlew :core:media:testDebugUnitTest)。
  • 应用程序单元测试全部通过 (./gradlew :app:testDebugUnitTest)。

PR created automatically by Jules for task 9835182981235804504 started by @Shangjin-Xiao


Summary by cubic

Prevents a crash on Android API 26–28 by removing calls to MediaFormat.containsKey() (API 29-only). Previously, malformed or missing keys caused NoSuchMethodError and a DoS; now we safely read optional fields and skip missing ones.

  • Replace all MediaFormat.containsKey() checks with runCatching { format.get* } .getOrNull() in FrameExporter, ColorSpaceDetector, and MetadataExtractor.
  • Detect HDR metadata via getByteBuffer(...) != null instead of containsKey.
  • Update ColorSpaceDetectorTest to align with safe retrieval.
  • Scope changes strictly to MediaFormat; no changes to standard collection containsKey calls.

Written for commit 0fd9c3d. Summary will update on new commits.

Review in cubic

Replaced `MediaFormat.containsKey()` usages with safe `runCatching` blocks.
`containsKey` requires API 29+ and throws `NoSuchMethodError` on older
devices (minSdk 26). When handling untrusted or malformed media files,
this uncaught error crashes the application, resulting in a local DoS.

Changes applied to:
- FrameExporter.kt
- ColorSpaceDetector.kt
- MetadataExtractor.kt

Also updated ColorSpaceDetectorTest.kt to match the new safe-fetching behavior.

Co-authored-by: Shangjin-Xiao <84136399+Shangjin-Xiao@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 07a4eab8-c0fd-493d-98ed-97ead1354c38


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant