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:
@@ -1580,6 +1580,9 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable {
|
||||
for (int i = component.getIntents().size() - 1; i >= 0; i--) {
|
||||
IntentFilter filter = component.getIntents().get(i);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,11 +242,20 @@ public class PackageSetting extends PackageSettingBase {
|
||||
}
|
||||
|
||||
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);
|
||||
if (oldMimeTypes == null) {
|
||||
throw new IllegalArgumentException("Unknown MIME group " + mimeGroup
|
||||
+ " 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);
|
||||
boolean hasChanges = !newMimeTypes.equals(oldMimeTypes);
|
||||
|
||||
Reference in New Issue
Block a user