Skip to content

Fix CDEX containerSize and mapOffset validation in DexBackedDexFile - #105

Merged
sgjesse merged 1 commit into
google:mainfrom
dsrbecky:main
Aug 25, 2026
Merged

sgjesse merged 1 commit into
google:mainfrom
dsrbecky:main

Conversation

@dsrbecky

Copy link
Copy Markdown
Collaborator

Commit e99622b8 introduced validation of mapOffset against containerSize. For Compact DEX (CDEX) files: 1. containerSize was capped at fileSize (which covers only the unshared section header and ID tables, excluding the data section). 2. mapOffset is relative to baseDataOffset (the data section), but mapSize was eagerly read from dexBuffer instead of dataBuffer, reading garbage data from absolute offset mapOffset. Update containerSize calculation for CDEX headers to encompass dataStart + dataSize, use dataBuffer to read mapSize at mapOffset, and use overflow-safe bounds checking.

Commit e99622b8 introduced validation of mapOffset against containerSize. For Compact DEX (CDEX) files: 1. containerSize was capped at fileSize (which covers only the unshared section header and ID tables, excluding the data section). 2. mapOffset is relative to baseDataOffset (the data section), but mapSize was eagerly read from dexBuffer instead of dataBuffer, reading garbage data from absolute offset mapOffset. Update containerSize calculation for CDEX headers to encompass dataStart + dataSize, use dataBuffer to read mapSize at mapOffset, and use overflow-safe bounds checking.

TAG=agy
CONV=63f64982-065a-4b9f-a2d3-6fa7ad565aa6

Bug: 535190835
Bug: 285129432
Test: ./gradlew :dexlib2:test --tests com.android.tools.smali.dexlib2.dexbacked.CDexTest
Flag: EXEMPT BUGFIX
Change-Id: I6249049af4d31d13cf0b66f36fbb0e2dd9dcb55a
@sgjesse
sgjesse merged commit 1a36aa3 into google:main Aug 25, 2026
7 checks passed
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.

2 participants