Limit length and number of MIME types you can set

Limit character length of MIME types to 255. If this length is exceeded
then a IllegalArugmentException is thrown. The number of MIME types that
can be set is also limited to 500 per MIME group with the number of
total MIME Groups also limited to 500. A IllegalStateException is thrown if this number is exceeded.

Bug: 237291548
Test: Installed and ran POC app from b/237291548
Change-Id: I1d57e674f778cfacdc89225ac3273c432a39af63
Merged-In: I1d57e674f778cfacdc89225ac3273c432a39af63
This commit is contained in:
William Loh
2022-08-05 20:25:27 +00:00
parent 5421a3f422
commit 9bdd9d274a
2 changed files with 12 additions and 0 deletions

View File

@@ -5797,6 +5797,11 @@ public class PackageManagerService implements PackageSender, TestUtilityService
final Computer snapshot = snapshotComputer(); final Computer snapshot = snapshotComputer();
enforceOwnerRights(snapshot, packageName, Binder.getCallingUid()); enforceOwnerRights(snapshot, packageName, Binder.getCallingUid());
mimeTypes = CollectionUtils.emptyIfNull(mimeTypes); mimeTypes = CollectionUtils.emptyIfNull(mimeTypes);
for (String mimeType : mimeTypes) {
if (mimeType.length() > 255) {
throw new IllegalArgumentException("MIME type length exceeds 255 characters");
}
}
final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName); final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
Set<String> existingMimeTypes = packageState.getMimeGroups().get(mimeGroup); Set<String> existingMimeTypes = packageState.getMimeGroups().get(mimeGroup);
if (existingMimeTypes == null) { if (existingMimeTypes == null) {
@@ -5807,6 +5812,10 @@ public class PackageManagerService implements PackageSender, TestUtilityService
&& existingMimeTypes.containsAll(mimeTypes)) { && existingMimeTypes.containsAll(mimeTypes)) {
return; return;
} }
if (mimeTypes.size() > 500) {
throw new IllegalStateException("Max limit on MIME types for MIME group "
+ mimeGroup + " exceeded for package " + packageName);
}
ArraySet<String> mimeTypesSet = new ArraySet<>(mimeTypes); ArraySet<String> mimeTypesSet = new ArraySet<>(mimeTypes);
commitPackageStateMutation(null, packageName, packageStateWrite -> { commitPackageStateMutation(null, packageName, packageStateWrite -> {

View File

@@ -1856,6 +1856,9 @@ public class ParsingPackageImpl implements ParsingPackage, ParsingPackageHidden,
for (int i = component.getIntents().size() - 1; i >= 0; i--) { for (int i = component.getIntents().size() - 1; i >= 0; i--) {
IntentFilter filter = component.getIntents().get(i).getIntentFilter(); IntentFilter filter = component.getIntents().get(i).getIntentFilter();
for (int groupIndex = filter.countMimeGroups() - 1; groupIndex >= 0; groupIndex--) { for (int groupIndex = filter.countMimeGroups() - 1; groupIndex >= 0; groupIndex--) {
if (mimeGroups != null && mimeGroups.size() > 500) {
throw new IllegalStateException("Max limit on number of MIME Groups reached");
}
mimeGroups = ArrayUtils.add(mimeGroups, filter.getMimeGroup(groupIndex)); mimeGroups = ArrayUtils.add(mimeGroups, filter.getMimeGroup(groupIndex));
} }
} }