Limit length and number of MIME types you can set am: 3ae3406b97

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19785208

Change-Id: I286025d3076ae0a174ff8a70d89187649011c4e5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
William Loh
2022-10-12 18:24:41 +00:00
committed by Automerger Merge Worker
2 changed files with 12 additions and 0 deletions

View File

@@ -1584,6 +1584,9 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable {
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); IntentFilter filter = component.getIntents().get(i);
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));
} }
} }

View File

@@ -242,11 +242,20 @@ public class PackageSetting extends PackageSettingBase {
} }
public boolean setMimeGroup(String mimeGroup, List<String> mimeTypes) { public boolean setMimeGroup(String mimeGroup, List<String> mimeTypes) {
for (String mimeType : mimeTypes) {
if (mimeType.length() > 255) {
throw new IllegalArgumentException("MIME type length exceeds 255 characters");
}
}
ArraySet<String> oldMimeTypes = getMimeGroupInternal(mimeGroup); ArraySet<String> oldMimeTypes = getMimeGroupInternal(mimeGroup);
if (oldMimeTypes == null) { if (oldMimeTypes == null) {
throw new IllegalArgumentException("Unknown MIME group " + mimeGroup throw new IllegalArgumentException("Unknown MIME group " + mimeGroup
+ " for package " + name); + " for package " + name);
} }
if (mimeTypes.size() > 500) {
throw new IllegalStateException("Max limit on MIME types for MIME group "
+ mimeGroup + " exceeded for package " + name);
}
ArraySet<String> newMimeTypes = new ArraySet<>(mimeTypes); ArraySet<String> newMimeTypes = new ArraySet<>(mimeTypes);
boolean hasChanges = !newMimeTypes.equals(oldMimeTypes); boolean hasChanges = !newMimeTypes.equals(oldMimeTypes);