summaryrefslogtreecommitdiff
path: root/tools/aapt2/util/Util.cpp
diff options
context:
space:
mode:
authorRhed Jao <rhedjao@google.com>2020-11-12 10:48:03 +0800
committerRhed Jao <rhedjao@google.com>2020-11-19 15:34:14 +0800
commit2c4344223d84204a9a317ceff2fa7183d1ee5621 (patch)
tree86431b70214b780f7e212943770ce4eaa3871a34 /tools/aapt2/util/Util.cpp
parentce2de700073f2c39282067dfe6be9d1cc7e7e4f6 (diff)
aapt2: Limit length of package name and shared user id
Package name and shared user id could be used as part of filename as prefix by other modules. Limits the length to 223 and reserves 32 for the OS. Bug: 118768971 Test: atest aapt2_tests Test: aapt2 link -I android.jar --manifest ManifestLongPackageName.xml Test: aapt2 link -I android.jar --manifest ManifestLongSharedUserId.xml Change-Id: Ic4b5b4647b9e253b79b663f4d7a9050f43bb8cf0
Diffstat (limited to 'tools/aapt2/util/Util.cpp')
-rw-r--r--tools/aapt2/util/Util.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/aapt2/util/Util.cpp b/tools/aapt2/util/Util.cpp
index 37ce65e4fe5b..8aa0fd5b34c8 100644
--- a/tools/aapt2/util/Util.cpp
+++ b/tools/aapt2/util/Util.cpp
@@ -38,6 +38,11 @@ using ::android::StringPiece16;
namespace aapt {
namespace util {
+// Package name and shared user id would be used as a part of the file name.
+// Limits size to 223 and reserves 32 for the OS.
+// See frameworks/base/core/java/android/content/pm/parsing/ParsingPackageUtils.java
+constexpr static const size_t kMaxPackageNameSize = 223;
+
static std::vector<std::string> SplitAndTransform(
const StringPiece& str, char sep, const std::function<char(char)>& f) {
std::vector<std::string> parts;
@@ -169,9 +174,21 @@ static int IsAndroidNameImpl(const StringPiece& str) {
}
bool IsAndroidPackageName(const StringPiece& str) {
+ if (str.size() > kMaxPackageNameSize) {
+ return false;
+ }
return IsAndroidNameImpl(str) > 1 || str == "android";
}
+bool IsAndroidSharedUserId(const android::StringPiece& package_name,
+ const android::StringPiece& shared_user_id) {
+ if (shared_user_id.size() > kMaxPackageNameSize) {
+ return false;
+ }
+ return shared_user_id.empty() || IsAndroidNameImpl(shared_user_id) > 1 ||
+ package_name == "android";
+}
+
bool IsAndroidSplitName(const StringPiece& str) {
return IsAndroidNameImpl(str) > 0;
}