Skip to content

Determinism and hardening improvements - #101

Merged
sgjesse merged 7 commits into
google:mainfrom
dsrbecky:main
Jun 26, 2026
Merged

sgjesse merged 7 commits into
google:mainfrom
dsrbecky:main

Conversation

@dsrbecky

Copy link
Copy Markdown
Collaborator

No description provided.

dsrbecky added 4 commits June 24, 2026 13:37
Replaced by the "Harden DexBackedDexFile against malformed DEX" commit.

This reverts commit 491ae88.
Ensure callSiteComparator tie-breaks deterministically on call site name
when encoded array offsets match, and align CallSiteReference equality.
Standardize data section sorting to lexicographical order across
writeEncodedArrays and CollectionUtils.compareAsSet, resolving a bug in
compareAsSet where pre-sorting size comparisons could crash or error.
Additionally, replace ArraySortedSet.of with copyOf in CollectionUtils
and PoolClassDef to ensure collections are genuinely sorted when wrapped.

Flag: EXEMPT BUGFIX
Test: repeated builds produce the same file/hash now
Change-Id: I85d39888f69a5e4aff90e273e9d6f4092f676215
TAG=agy
CONV=396b0ad6-b46c-4693-90c5-77ac4f18be23
Resolve pre-existing bugs in ArraySortedSet where isEmpty() returned
true for non-empty sets and toArray(T[] a) had inverted array boundary
checks. Add unit tests for both methods in ArraySortedSetTest.

Flag: EXEMPT BUGFIX
Test: ./gradlew :dexlib2:test --tests com.android.tools.smali.util.ArraySortedSetTest
TAG=agy
CONV=92fcec37-cdaa-44ee-9f03-128bec8492e3

Change-Id: I1c375e8bddbb1373081b2688b18593f18a601ee5
Introduce ZipDexEntry interface extending DexEntry to expose the
uncompressed ZIP entry CRC-32 checksum via getCrc(). Update
ZipDexContainer to instantiate ZipDexEntry objects when reading ZIP
archives, allowing callers to inspect entry checksums. Add unit test
coverage in ZipDexContainerTest.

Flag: EXEMPT PURE_REFACTOR
Test: ./gradlew :dexlib2:test --tests com.android.tools.smali.dexlib2.dexbacked.ZipDexContainerTest
TAG=agy
CONV=92fcec37-cdaa-44ee-9f03-128bec8492e3

Change-Id: If4205d80fccafa4e80be7684ec81b3a6e46c173e
@google-cla

google-cla Bot commented Jun 24, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

dsrbecky added 3 commits June 24, 2026 13:54
Update smaliTreeWalker grammar definition to access totalMethodRegisters and methodParameterRegisters via ANTLR $method dynamic attribute scoping rather than referencing the generated internal method_stack stack structure directly.

Change-Id: I8bceb392e69e0b71700c0da195964efacfe6680d
Update ZipDexContainer.getEntries() to store entries in insertion
order via LinkedHashMap. Scan ZIP archives to load classes.dex,
classes2.dex, etc. sequentially until classesN.dex is missing, then
load remaining DEX files in lexicographically sorted order. When
loading virtual DEX entries from container DEX files, check whether
the entry is both isDexContainerFirstEntry and isDexContainerLastEntry;
if so, omit the entry suffix (/0, /1, etc.), otherwise append the
suffix. Load DEX entries only up to the container range and ignore
any trailing garbage, aligning with ART's loader behavior.
Add unit test coverage in ZipDexContainerTest.

Flag: EXEMPT PURE_REFACTOR
Test: ./gradlew :dexlib2:test --tests com.android.tools.smali.dexlib2.dexbacked.ZipDexContainerTest
TAG=agy
CONV=de2c422c-7039-42f4-a565-4aeb48b07bc7

Change-Id: I5550a749deda3dc283744dc46924177a2a63f0c4
Harden DexBackedDexFile against malformed and corrupted DEX files to
prevent unchecked runtime crashes (such as OutOfBounds exceptions).
Ensure buffer capacity checks guard magic parsing and version checking.
Align constructor validation to enforce minimum header sizes and bounds
checking relative to header_offset. Uphold specification constraints on
container DEX files (v41+) and lazy load map items on demand.

Test: ./gradlew :dexlib2:test
Flag: EXEMPT BUGFIX
TAG=agy
CONV=af5f83f4-d40c-419f-9452-99168f7eb18f

Change-Id: I15a7c9226aa61ec44d086c2e5daa6cf34b9f0987
@sgjesse
sgjesse self-requested a review June 26, 2026 08:22
@sgjesse sgjesse self-assigned this Jun 26, 2026
@sgjesse
sgjesse merged commit 5021f36 into google:main Jun 26, 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