Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9c83f96 authored by William Loh's avatar William Loh
Browse files

Restrict mimeGroup name length to 1024

Also set mimeType length to 255 to match the length limit imposed in the
setMimeGroup API.

Bug: 316152378
Bug: 267185315
Test: atest AndroidPackageParsingValidationTest
Change-Id: I5a630b24f2abdae3f4dff18064b632c9d1749b76
parent d1dddaff
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import androidx.annotation.StyleableRes;

import com.android.internal.R;

import java.util.Set;

/**
 * Defines the string attribute length and child tag count restrictions for a xml element.
 *
@@ -37,7 +39,11 @@ public class Element {
    private static final int MAX_ATTR_LEN_URL_COMPONENT = 256;
    private static final int MAX_ATTR_LEN_PERMISSION_GROUP = 256;
    private static final int MAX_ATTR_LEN_PACKAGE = 256;
    private static final int MAX_ATTR_LEN_MIMETYPE = 512;
    /**
     * The mime type max length restriction here should match the restriction that is also
     * placed in {@link android.content.pm.PackageManager#setMimeGroup(String, Set)}
     */
    private static final int MAX_ATTR_LEN_MIMETYPE = 255;
    private static final int MAX_ATTR_LEN_NAME = 1024;
    private static final int MAX_ATTR_LEN_PATH = 4000;
    private static final int MAX_ATTR_LEN_VALUE = 32_768;
@@ -103,6 +109,7 @@ public class Element {
    protected static final String TAG_ATTR_HOST = "host";
    protected static final String TAG_ATTR_MANAGE_SPACE_ACTIVITY = "manageSpaceActivity";
    protected static final String TAG_ATTR_MIMETYPE = "mimeType";
    protected static final String TAG_ATTR_MIMEGROUP = "mimeGroup";
    protected static final String TAG_ATTR_NAME = "name";
    protected static final String TAG_ATTR_PACKAGE = "package";
    protected static final String TAG_ATTR_PATH = "path";
@@ -367,6 +374,7 @@ public class Element {
            case TAG_ATTR_BACKUP_AGENT:
            case TAG_ATTR_CATEGORY:
            case TAG_ATTR_MANAGE_SPACE_ACTIVITY:
            case TAG_ATTR_MIMEGROUP:
            case TAG_ATTR_NAME:
            case TAG_ATTR_PARENT_ACTIVITY_NAME:
            case TAG_ATTR_PERMISSION:
@@ -520,6 +528,8 @@ public class Element {
                return MAX_ATTR_LEN_URL_COMPONENT;
            case R.styleable.AndroidManifestData_mimeType:
                return MAX_ATTR_LEN_MIMETYPE;
            case R.styleable.AndroidManifestData_mimeGroup:
                return MAX_ATTR_LEN_NAME;
            case R.styleable.AndroidManifestData_path:
            case R.styleable.AndroidManifestData_pathPattern:
            case R.styleable.AndroidManifestData_pathPrefix:
+3 −2
Original line number Diff line number Diff line
@@ -157,7 +157,7 @@ class AndroidPackageParsingValidationTest {
        validateTagCount("uses-library", 1000, tag)
        validateTagCount("activity-alias", 4000, tag)
        validateTagCount("provider", 8000, tag)
        validateTagCount("activity", 40000, tag)
        validateTagCount("activity", 30000, tag)
    }

    @Test
@@ -465,7 +465,8 @@ class AndroidPackageParsingValidationTest {
            R.styleable.AndroidManifestData_pathAdvancedPattern,
            4000
        )
        validateTagAttr(tag, "mimeType", R.styleable.AndroidManifestData_mimeType, 512)
        validateTagAttr(tag, "mimeType", R.styleable.AndroidManifestData_mimeType, 255)
        validateTagAttr(tag, "mimeGroup", R.styleable.AndroidManifestData_mimeGroup, 1024)
    }

    @Test