🛡️ Sentinel: [MEDIUM] Fix MediaFormat API compatibility causing DoS - #69
🛡️ Sentinel: [MEDIUM] Fix MediaFormat API compatibility causing DoS#69Shangjin-Xiao wants to merge 1 commit into
Conversation
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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 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. Comment |
🚨 严重程度
MEDIUM
💡 漏洞
代码中使用了
MediaFormat.containsKey(),该方法在 Android API 29 中才被引入,而项目的minSdk是 26。当应用程序在较低版本的 Android 系统上解析不受信任或格式错误的媒体文件时,如果缺少某些键值,执行到该方法会抛出NoSuchMethodError。🎯 影响
由于无法捕获这种
LinkageError级别的异常,应用程序会直接崩溃。恶意构造的媒体文件可以利用这一点在本地引发拒绝服务(DoS)攻击,或者让老设备用户在正常导出/提取帧时频繁遭遇应用闪退。🛠️ 修复
FrameExporter、ColorSpaceDetector和MetadataExtractor中对MediaFormat.containsKey()的调用。runCatching { format.get*(key) }.getOrNull()范式进行替换。这不仅安全地尝试获取所需的元数据,还通过内部吸收异常防止了应用崩溃。ColorSpaceDetectorTest.kt中的 mock 行为,确保单元测试通过。MediaFormat范围内,未影响其他正常使用containsKey的集合(如Map、ConcurrentHashMap缓存)。✅ 验证
./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 causedNoSuchMethodErrorand a DoS; now we safely read optional fields and skip missing ones.MediaFormat.containsKey()checks withrunCatching { format.get* } .getOrNull()in FrameExporter, ColorSpaceDetector, and MetadataExtractor.getByteBuffer(...) != nullinstead ofcontainsKey.ColorSpaceDetectorTestto align with safe retrieval.MediaFormat; no changes to standard collectioncontainsKeycalls.Written for commit 0fd9c3d. Summary will update on new commits.