Skip to content

Commit

Permalink
Fix issue using AttributeSetBuilder with compact resource table entries
Browse files Browse the repository at this point in the history
AttributeSetBuilder uses CppAssetManager, which did not support compact
resource table entries.

PiperOrigin-RevId: 573103527
  • Loading branch information
hoisie authored and Copybara-Service committed Oct 13, 2023
1 parent c4d1cb2 commit 638ce69
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions resources/src/main/java/org/robolectric/res/android/ResTable.java
Expand Up @@ -712,19 +712,20 @@ private int getEntry(
// reinterpret_cast<const uint8_t*>(bestType) + bestOffset);
final ResTable_entry entry = new ResTable_entry(bestType.myBuf(),
bestType.myOffset() + bestOffset);
if (dtohs(entry.size) < ResTable_entry.SIZEOF) {
int entrySize = entry.isCompact() ? ResTable_entry.SIZEOF : dtohs(entry.size);
if (entrySize < ResTable_entry.SIZEOF) {
ALOGW("ResTable_entry size 0x%x is too small", dtohs(entry.size));
return BAD_TYPE;
}

if (outEntry != null) {
outEntry.entry = entry;
outEntry.config = bestConfig;
outEntry.type = bestType;
outEntry.specFlags = specFlags;
outEntry._package_ = bestPackage;
outEntry.typeStr = new StringPoolRef(bestPackage.typeStrings, actualTypeIndex - bestPackage.typeIdOffset);
outEntry.keyStr = new StringPoolRef(bestPackage.keyStrings, dtohl(entry.key.index));
outEntry.keyStr = new StringPoolRef(bestPackage.keyStrings, dtohl(entry.getKeyIndex()));
}
return NO_ERROR;
}
Expand Down Expand Up @@ -960,10 +961,12 @@ int parsePackage(ResTable_package pkg,
dtohs(type.header.headerSize),
typeSize));
}
if (dtohs(type.header.headerSize)+(4/*sizeof(int)*/*newEntryCount) > typeSize) {
ALOGW("ResTable_type entry index to %s extends beyond chunk end 0x%x.",
(dtohs(type.header.headerSize) + (4/*sizeof(int)*/*newEntryCount)),
typeSize);
// Check if the table uses compact encoding.
int bytesPerEntry = isTruthy(type.flags & ResTable_type.FLAG_OFFSET16) ? 2 : 4;
if (dtohs(type.header.headerSize) + (bytesPerEntry * newEntryCount) > typeSize) {
ALOGW(
"ResTable_type entry index to %s extends beyond chunk end 0x%x.",
(dtohs(type.header.headerSize) + (bytesPerEntry * newEntryCount)), typeSize);
return (mError=BAD_TYPE);
}

Expand Down

0 comments on commit 638ce69

Please sign in to comment.