Skip to content

Commit 0e216ea

Browse files
jeffyhaoAndroid (Google) Code Review
authored and
Android (Google) Code Review
committed
Merge "Ignore invalid access flags." into klp-dev
2 parents dfec26e + 4b44ea2 commit 0e216ea

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

libdex/DexSwapVerify.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,9 @@ static void* swapClassDefItem(const CheckState* state, void* ptr) {
912912
SWAP_OFFSET4(item->classDataOff);
913913

914914
if ((item->accessFlags & ~ACC_CLASS_MASK) != 0) {
915-
ALOGE("Bogus class access flags %x", item->accessFlags);
916-
return NULL;
915+
// The VM specification says that unknown flags should be ignored.
916+
ALOGV("Bogus class access flags %x", item->accessFlags);
917+
item->accessFlags &= ACC_CLASS_MASK;
917918
}
918919

919920
return item + 1;
@@ -1457,8 +1458,9 @@ static bool verifyFields(const CheckState* state, u4 size,
14571458
}
14581459

14591460
if ((accessFlags & ~ACC_FIELD_MASK) != 0) {
1460-
ALOGE("Bogus field access flags %x @ %d", accessFlags, i);
1461-
return false;
1461+
// The VM specification says that unknown flags should be ignored.
1462+
ALOGV("Bogus field access flags %x @ %d", accessFlags, i);
1463+
field->accessFlags &= ACC_FIELD_MASK;
14621464
}
14631465
}
14641466

@@ -1487,12 +1489,17 @@ static bool verifyMethods(const CheckState* state, u4 size,
14871489
return false;
14881490
}
14891491

1490-
if (((accessFlags & ~ACC_METHOD_MASK) != 0)
1491-
|| (isSynchronized && !allowSynchronized)) {
1492-
ALOGE("Bogus method access flags %x @ %d", accessFlags, i);
1492+
if (isSynchronized && !allowSynchronized) {
1493+
ALOGE("Bogus method access flags (synchronization) %x @ %d", accessFlags, i);
14931494
return false;
14941495
}
14951496

1497+
if ((accessFlags & ~ACC_METHOD_MASK) != 0) {
1498+
// The VM specification says that unknown flags should be ignored.
1499+
ALOGV("Bogus method access flags %x @ %d", accessFlags, i);
1500+
method->accessFlags &= ACC_METHOD_MASK;
1501+
}
1502+
14961503
if (expectCode) {
14971504
if (method->codeOff == 0) {
14981505
ALOGE("Unexpected zero code_off for access_flags %x",

vm/oo/Class.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,9 @@ static ClassObject* loadClassFromDex0(DvmDex* pDvmDex,
17401740
* Make sure the aren't any "bonus" flags set, since we use them for
17411741
* runtime state.
17421742
*/
1743+
/* bits we can reasonably expect to see set in a DEX access flags field */
1744+
const uint32_t EXPECTED_FILE_FLAGS = (ACC_CLASS_MASK | CLASS_ISPREVERIFIED |
1745+
CLASS_ISOPTIMIZED);
17431746
if ((pClassDef->accessFlags & ~EXPECTED_FILE_FLAGS) != 0) {
17441747
ALOGW("Invalid file flags in class %s: %04x",
17451748
descriptor, pClassDef->accessFlags);

vm/oo/Object.h

-4
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ enum ClassFlags {
8282
CLASS_ISPREVERIFIED = (1<<16), // class has been pre-verified
8383
};
8484

85-
/* bits we can reasonably expect to see set in a DEX access flags field */
86-
#define EXPECTED_FILE_FLAGS \
87-
(ACC_CLASS_MASK | CLASS_ISPREVERIFIED | CLASS_ISOPTIMIZED)
88-
8985
/*
9086
* Get/set class flags.
9187
*/

0 commit comments

Comments
 (0)