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

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

Place limits on the new uri-relative-filter-group tags.

Limit the number of uri relative filter groups to 100 per intent filter.
The number of data elements per group will also be limited to 100.

Bug: 307556883
Test: atest AndroidPackageParsingValidationTest
Change-Id: Iaaca4be1e108d733999f639b225f9bb7a6f6c563
parent 363f1d68
Loading
Loading
Loading
Loading
+40 −2
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ public class Element {
    protected static final String TAG_SUPPORTS_GL_TEXTURE = "supports-gl-texture";
    protected static final String TAG_SUPPORTS_INPUT = "supports-input";
    protected static final String TAG_SUPPORTS_SCREENS = "supports-screens";
    protected static final String TAG_URI_RELATIVE_FILTER_GROUP = "uri-relative-filter-group";
    protected static final String TAG_USES_CONFIGURATION = "uses-configuration";
    protected static final String TAG_USES_FEATURE = "uses-feature";
    protected static final String TAG_USES_GL_TEXTURE = "uses-gl-texture";
@@ -106,6 +107,11 @@ public class Element {

    protected static final String TAG_ATTR_BACKUP_AGENT = "backupAgent";
    protected static final String TAG_ATTR_CATEGORY = "category";
    protected static final String TAG_ATTR_FRAGMENT = "fragment";
    protected static final String TAG_ATTR_FRAGMENT_ADVANCED_PATTERN = "fragmentAdvancedPattern";
    protected static final String TAG_ATTR_FRAGMENT_PATTERN = "fragmentPattern";
    protected static final String TAG_ATTR_FRAGMENT_PREFIX = "fragmentPrefix";
    protected static final String TAG_ATTR_FRAGMENT_SUFFIX = "fragmentSuffix";
    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";
@@ -122,6 +128,11 @@ public class Element {
    protected static final String TAG_ATTR_PERMISSION_GROUP = "permissionGroup";
    protected static final String TAG_ATTR_PORT = "port";
    protected static final String TAG_ATTR_PROCESS = "process";
    protected static final String TAG_ATTR_QUERY = "query";
    protected static final String TAG_ATTR_QUERY_ADVANCED_PATTERN = "queryAdvancedPattern";
    protected static final String TAG_ATTR_QUERY_PATTERN = "queryPattern";
    protected static final String TAG_ATTR_QUERY_PREFIX = "queryPrefix";
    protected static final String TAG_ATTR_QUERY_SUFFIX = "querySuffix";
    protected static final String TAG_ATTR_READ_PERMISSION = "readPermission";
    protected static final String TAG_ATTR_REQUIRED_ACCOUNT_TYPE = "requiredAccountType";
    protected static final String TAG_ATTR_REQUIRED_SYSTEM_PROPERTY_NAME =
@@ -143,7 +154,7 @@ public class Element {

    // The length of mTagCounters corresponds to the number of tags defined in getCounterIdx. If new
    // tags are added then the size here should be increased to match.
    private final TagCounter[] mTagCounters = new TagCounter[34];
    private final TagCounter[] mTagCounters = new TagCounter[35];

    String mTag;

@@ -238,9 +249,11 @@ public class Element {
                return 31;
            case TAG_INTENT:
                return 32;
            case TAG_URI_RELATIVE_FILTER_GROUP:
                return 33;
            default:
                // The size of the mTagCounters array should be equal to this value+1
                return 33;
                return 34;
        }
    }

@@ -276,6 +289,7 @@ public class Element {
            case TAG_SERVICE:
            case TAG_SUPPORTS_GL_TEXTURE:
            case TAG_SUPPORTS_SCREENS:
            case TAG_URI_RELATIVE_FILTER_GROUP:
            case TAG_USES_CONFIGURATION:
            case TAG_USES_FEATURE:
            case TAG_USES_LIBRARY:
@@ -322,6 +336,7 @@ public class Element {
                break;
            case TAG_INTENT:
            case TAG_INTENT_FILTER:
                initializeCounter(TAG_URI_RELATIVE_FILTER_GROUP, 100);
                initializeCounter(TAG_ACTION, 20000);
                initializeCounter(TAG_CATEGORY, 40000);
                initializeCounter(TAG_DATA, 40000);
@@ -354,6 +369,9 @@ public class Element {
                initializeCounter(TAG_INTENT, 2000);
                initializeCounter(TAG_PROVIDER, 8000);
                break;
            case TAG_URI_RELATIVE_FILTER_GROUP:
                initializeCounter(TAG_DATA, 100);
                break;
        }
    }

@@ -391,11 +409,21 @@ public class Element {
            case TAG_ATTR_VERSION_NAME:
            case TAG_ATTR_ZYGOTE_PRELOAD_NAME:
                return MAX_ATTR_LEN_NAME;
            case TAG_ATTR_FRAGMENT:
            case TAG_ATTR_FRAGMENT_ADVANCED_PATTERN:
            case TAG_ATTR_FRAGMENT_PATTERN:
            case TAG_ATTR_FRAGMENT_PREFIX:
            case TAG_ATTR_FRAGMENT_SUFFIX:
            case TAG_ATTR_PATH:
            case TAG_ATTR_PATH_ADVANCED_PATTERN:
            case TAG_ATTR_PATH_PATTERN:
            case TAG_ATTR_PATH_PREFIX:
            case TAG_ATTR_PATH_SUFFIX:
            case TAG_ATTR_QUERY:
            case TAG_ATTR_QUERY_ADVANCED_PATTERN:
            case TAG_ATTR_QUERY_PATTERN:
            case TAG_ATTR_QUERY_PREFIX:
            case TAG_ATTR_QUERY_SUFFIX:
                return MAX_ATTR_LEN_PATH;
            case TAG_ATTR_VALUE:
                return MAX_ATTR_LEN_VALUE;
@@ -535,6 +563,16 @@ public class Element {
            case R.styleable.AndroidManifestData_pathPrefix:
            case R.styleable.AndroidManifestData_pathSuffix:
            case R.styleable.AndroidManifestData_pathAdvancedPattern:
            case R.styleable.AndroidManifestData_query:
            case R.styleable.AndroidManifestData_queryPattern:
            case R.styleable.AndroidManifestData_queryPrefix:
            case R.styleable.AndroidManifestData_querySuffix:
            case R.styleable.AndroidManifestData_queryAdvancedPattern:
            case R.styleable.AndroidManifestData_fragment:
            case R.styleable.AndroidManifestData_fragmentPattern:
            case R.styleable.AndroidManifestData_fragmentPrefix:
            case R.styleable.AndroidManifestData_fragmentSuffix:
            case R.styleable.AndroidManifestData_fragmentAdvancedPattern:
                return MAX_ATTR_LEN_PATH;
            default:
                return DEFAULT_MAX_STRING_ATTR_LENGTH;
+55 −0
Original line number Diff line number Diff line
@@ -436,6 +436,13 @@ class AndroidPackageParsingValidationTest {
        validateTagCount("action", 20000, tag)
        validateTagCount("category", 40000, tag)
        validateTagCount("data", 40000, tag)
        validateTagCount("uri-relative-filter-group", 100, tag)
    }

    @Test
    fun parseUriRelativeFilterGroupTag() {
        val tag = "uri-relative-filter-group"
        validateTagCount("data", 100, tag)
    }

    @Test
@@ -465,6 +472,54 @@ class AndroidPackageParsingValidationTest {
            R.styleable.AndroidManifestData_pathAdvancedPattern,
            4000
        )
        validateTagAttr(tag, "query", R.styleable.AndroidManifestData_query, 4000)
        validateTagAttr(
            tag,
            "queryPattern",
            R.styleable.AndroidManifestData_queryPattern,
            4000
        )
        validateTagAttr(
            tag,
            "queryPrefix",
            R.styleable.AndroidManifestData_queryPrefix,
            4000
        )
        validateTagAttr(tag,
            "querySuffix",
            R.styleable.AndroidManifestData_querySuffix,
            4000
        )
        validateTagAttr(
            tag,
            "queryAdvancedPattern",
            R.styleable.AndroidManifestData_queryAdvancedPattern,
            4000
        )
        validateTagAttr(tag, "fragment", R.styleable.AndroidManifestData_query, 4000)
        validateTagAttr(
            tag,
            "fragmentPattern",
            R.styleable.AndroidManifestData_fragmentPattern,
            4000
        )
        validateTagAttr(
            tag,
            "fragmentPrefix",
            R.styleable.AndroidManifestData_fragmentPrefix,
            4000
        )
        validateTagAttr(tag,
            "fragmentSuffix",
            R.styleable.AndroidManifestData_fragmentSuffix,
            4000
        )
        validateTagAttr(
            tag,
            "fragmentAdvancedPattern",
            R.styleable.AndroidManifestData_fragmentAdvancedPattern,
            4000
        )
        validateTagAttr(tag, "mimeType", R.styleable.AndroidManifestData_mimeType, 255)
        validateTagAttr(tag, "mimeGroup", R.styleable.AndroidManifestData_mimeGroup, 1024)
    }