diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-03-29 13:00:35 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-03-29 20:11:04 +0000 |
commit | 33af6c730f9f7fc51f04516c7a22cac82cb9823e (patch) | |
tree | 94f834ef6df06b8b534cb3a053de308f74793a09 /tools/aapt2/unflatten/BinaryResourceParser.cpp | |
parent | c463bed8dbfbb5bbac791299e8997282685e64d2 (diff) |
AAPT2: Parse an ID encoded as a map
ID types should not be encoded as a map. AAPT and AAPT2 emit
IDs as boolean types.
Some apps exist that for some reason have their ID types encoded
as empty maps. This is the case only for the auto generated IDs
from enum values in <attr> tags.
Allow IDs as maps and ignore their content when processing an APK
for optimizing.
Also fixes an issue with expected size of the ResTable_package struct.
Bug: 35861796
Test: tested against the APK in b/35861796
Change-Id: I29a19cd9777bb10bed6766cd42e35e50e098797b
Diffstat (limited to 'tools/aapt2/unflatten/BinaryResourceParser.cpp')
-rw-r--r-- | tools/aapt2/unflatten/BinaryResourceParser.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tools/aapt2/unflatten/BinaryResourceParser.cpp b/tools/aapt2/unflatten/BinaryResourceParser.cpp index 66bcfa034dfb..35bf618c1635 100644 --- a/tools/aapt2/unflatten/BinaryResourceParser.cpp +++ b/tools/aapt2/unflatten/BinaryResourceParser.cpp @@ -168,10 +168,11 @@ bool BinaryResourceParser::ParseTable(const ResChunk_header* chunk) { } bool BinaryResourceParser::ParsePackage(const ResChunk_header* chunk) { - const ResTable_package* package_header = ConvertTo<ResTable_package>(chunk); + constexpr size_t kMinPackageSize = + sizeof(ResTable_package) - sizeof(ResTable_package::typeIdOffset); + const ResTable_package* package_header = ConvertTo<ResTable_package, kMinPackageSize>(chunk); if (!package_header) { - context_->GetDiagnostics()->Error(DiagMessage(source_) - << "corrupt ResTable_package chunk"); + context_->GetDiagnostics()->Error(DiagMessage(source_) << "corrupt ResTable_package chunk"); return false; } @@ -498,8 +499,14 @@ std::unique_ptr<Value> BinaryResourceParser::ParseMapEntry( return ParseArray(name, config, map); case ResourceType::kPlurals: return ParsePlural(name, config, map); + case ResourceType::kId: + // Special case: An ID is not a bag, but some apps have defined the auto-generated + // IDs that come from declaring an enum value in an attribute as an empty map... + // We can ignore the value here. + return util::make_unique<Id>(); default: - LOG(FATAL) << "unknown map type"; + context_->GetDiagnostics()->Error(DiagMessage() << "illegal map type '" << ToString(name.type) + << "' (" << (int)name.type << ")"); break; } return {}; |