Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue using AttributeSetBuilder with compact resource table entries #8521

Merged
merged 1 commit into from Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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