summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dipankar Bhardwaj <dipankarb@google.com> 2024-12-17 13:42:56 +0000
committer Dipankar Bhardwaj <dipankarb@google.com> 2024-12-17 06:35:08 -0800
commitb9323135ddd4200d60d7bb42401a1d12447ea36d (patch)
tree89cca70ab7efd001b5e85d557c8efe44d41178a9
parent1266e17ffa56d1700ea28f6648a603ba07872de4 (diff)
Fix infinite loop for corrupted cachequota.xml
Test: atest com.android.server.storage.CacheQuotaStrategyTest Bug: 377194530 Flag: EXEMPT bug fix Change-Id: I38e5ae1bdfc032f816377af958cc81db8ac700aa
-rw-r--r--services/core/java/com/android/server/storage/CacheQuotaStrategy.java5
-rw-r--r--services/tests/servicestests/src/com/android/server/storage/CacheQuotaStrategyTest.java20
2 files changed, 20 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/storage/CacheQuotaStrategy.java b/services/core/java/com/android/server/storage/CacheQuotaStrategy.java
index dad3a784cfb9..bb163ef4c1d5 100644
--- a/services/core/java/com/android/server/storage/CacheQuotaStrategy.java
+++ b/services/core/java/com/android/server/storage/CacheQuotaStrategy.java
@@ -369,10 +369,9 @@ 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);
}
- quotas.add(request);
}
}
eventType = parser.next();
diff --git a/services/tests/servicestests/src/com/android/server/storage/CacheQuotaStrategyTest.java b/services/tests/servicestests/src/com/android/server/storage/CacheQuotaStrategyTest.java
index 9c61d95bc5e5..9528a05d38a0 100644
--- a/services/tests/servicestests/src/com/android/server/storage/CacheQuotaStrategyTest.java
+++ b/services/tests/servicestests/src/com/android/server/storage/CacheQuotaStrategyTest.java
@@ -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,8 +123,24 @@ 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();
}
-} \ No newline at end of file
+}