From 701a7fe39d30509a9a6bc4e612fe93166a5cdbd3 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Mon, 14 Sep 2020 11:55:43 -0700 Subject: Ignore resources from unknown types When loading binary APKs into aapt2 for dumping purposes, aapt2 allows the presence of custom resource types in the resources.arsc. Since apapt2 may not be able to correctly interpret the data of custom types, ignore resources from custom types completely when constructing the ResourceTable data structure for the APK. Bug: 168247188 Bug: 36051266 Test: run aapt2 dump bading/resources on APKs from both bugs Merged-In: Ia3c0b4e07457eb8634b5a256ef77270e99b8bd72 Change-Id: Ia3c0b4e07457eb8634b5a256ef77270e99b8bd72 --- tools/aapt2/Resource.cpp | 2 -- tools/aapt2/Resource.h | 5 ----- tools/aapt2/format/binary/BinaryResourceParser.cpp | 21 ++++++++++----------- 3 files changed, 10 insertions(+), 18 deletions(-) (limited to 'tools') diff --git a/tools/aapt2/Resource.cpp b/tools/aapt2/Resource.cpp index ae01170a6894..b78f48ce7f17 100644 --- a/tools/aapt2/Resource.cpp +++ b/tools/aapt2/Resource.cpp @@ -96,8 +96,6 @@ StringPiece to_string(ResourceType type) { return "styleable"; case ResourceType::kTransition: return "transition"; - case ResourceType::kUnknown: - return "unknown"; case ResourceType::kXml: return "xml"; } diff --git a/tools/aapt2/Resource.h b/tools/aapt2/Resource.h index 67ba895e51d1..a8ba202d08f7 100644 --- a/tools/aapt2/Resource.h +++ b/tools/aapt2/Resource.h @@ -66,11 +66,6 @@ enum class ResourceType { kStyle, kStyleable, kTransition, - - // Not a parsed type. It is only used when loading resource tables that may have modified type - // names - kUnknown, - kXml, }; diff --git a/tools/aapt2/format/binary/BinaryResourceParser.cpp b/tools/aapt2/format/binary/BinaryResourceParser.cpp index fd8e36ebf823..82c21a66b9f9 100644 --- a/tools/aapt2/format/binary/BinaryResourceParser.cpp +++ b/tools/aapt2/format/binary/BinaryResourceParser.cpp @@ -352,15 +352,15 @@ bool BinaryResourceParser::ParseType(const ResourceTablePackage* package, config.copyFromDtoH(type->config); const std::string type_str = util::GetString(type_pool_, type->id - 1); - - // Be lenient on the name of the type if the table is lenient on resource validation. - auto parsed_type = ResourceType::kUnknown; - if (const ResourceType* parsed = ParseResourceType(type_str)) { - parsed_type = *parsed; - } else if (table_->GetValidateResources()) { - diag_->Error(DiagMessage(source_) << "invalid type name '" << type_str << "' for type with ID " - << (int) type->id); - return false; + const ResourceType* parsed_type = ParseResourceType(type_str); + if (!parsed_type) { + // Be lenient on the name of the type if the table is lenient on resource validation. + bool log_error = table_->GetValidateResources(); + if (log_error) { + diag_->Error(DiagMessage(source_) << "invalid type name '" << type_str + << "' for type with ID " << type->id); + } + return !log_error; } TypeVariant tv(type); @@ -370,9 +370,8 @@ bool BinaryResourceParser::ParseType(const ResourceTablePackage* package, continue; } - const ResourceName name(package->name, parsed_type, + const ResourceName name(package->name, *parsed_type, util::GetString(key_pool_, util::DeviceToHost32(entry->key.index))); - const ResourceId res_id(package->id.value(), type->id, static_cast(it.index())); std::unique_ptr resource_value; -- cgit v1.2.3