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

Commit b9323135 authored by Dipankar Bhardwaj's avatar Dipankar Bhardwaj
Browse files

Fix infinite loop for corrupted cachequota.xml

Test: atest com.android.server.storage.CacheQuotaStrategyTest
Bug: 377194530
Flag: EXEMPT bug fix
Change-Id: I38e5ae1bdfc032f816377af958cc81db8ac700aa
parent 1266e17f
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();