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

Commit 28e18c5e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix infinite loop for corrupted cachequota.xml" into main

parents fdf50981 b9323135
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -369,12 +369,11 @@ public class CacheQuotaStrategy implements RemoteCallback.OnResultListener {
                tagName = parser.getName();
                if (TAG_QUOTA.equals(tagName)) {
                    CacheQuotaHint request = getRequestFromXml(parser);
                    if (request == null) {
                        continue;
                    }
                    if (request != null) {
                        quotas.add(request);
                    }
                }
            }
            eventType = parser.next();
        } while (eventType != XmlPullParser.END_DOCUMENT);
        return new Pair<>(previousBytes, quotas);
+18 −2
Original line number Diff line number Diff line
@@ -23,13 +23,13 @@ import android.test.AndroidTestCase;
import android.util.Pair;
import android.util.Xml;

import com.android.internal.util.FastXmlSerializer;
import com.android.modules.utils.TypedXmlSerializer;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.xmlpull.v1.XmlPullParserException;

import java.io.ByteArrayInputStream;
import java.io.StringWriter;
@@ -123,6 +123,22 @@ public class CacheQuotaStrategyTest extends AndroidTestCase {
                buildCacheQuotaHint("uuid2", 10, 250));
    }

    @Test
    public void testReadInvalidInput() throws Exception {
        String input = "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" +
                "<cache-info previousBytes=\"1000\">\n"
                + "<quota/>\n"
                + "</cache-info>\n";

        try {
            CacheQuotaStrategy.readFromXml(new ByteArrayInputStream(
                    input.getBytes("UTF-8")));
            fail("Expected XML parsing exception");
        } catch (XmlPullParserException e) {
            // Expected XmlPullParserException exception
        }
    }

    private CacheQuotaHint buildCacheQuotaHint(String volumeUuid, int uid, long quota) {
        return new CacheQuotaHint.Builder()
                .setVolumeUuid(volumeUuid).setUid(uid).setQuota(quota).build();