Merge "Fix a bug in RuleIndexingController where StackOverflowError occurs" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
065b6513ee
@@ -92,6 +92,9 @@ public class RuleIndexingController {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (keyToIndexMap.size() < 2) {
|
||||||
|
throw new IllegalStateException("Indexing file is corrupt.");
|
||||||
|
}
|
||||||
return keyToIndexMap;
|
return keyToIndexMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,6 +109,9 @@ public class RuleIndexingController {
|
|||||||
|
|
||||||
private static List<String> searchKeysRangeContainingKey(
|
private static List<String> searchKeysRangeContainingKey(
|
||||||
List<String> sortedKeyList, String key, int startIndex, int endIndex) {
|
List<String> sortedKeyList, String key, int startIndex, int endIndex) {
|
||||||
|
if (endIndex <= startIndex) {
|
||||||
|
throw new IllegalStateException("Indexing file is corrupt.");
|
||||||
|
}
|
||||||
if (endIndex - startIndex == 1) {
|
if (endIndex - startIndex == 1) {
|
||||||
return Arrays.asList(sortedKeyList.get(startIndex), sortedKeyList.get(endIndex));
|
return Arrays.asList(sortedKeyList.get(startIndex), sortedKeyList.get(endIndex));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import static com.android.server.integrity.utils.TestUtils.getValueBits;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertThrows;
|
||||||
|
|
||||||
import android.content.integrity.AppInstallMetadata;
|
import android.content.integrity.AppInstallMetadata;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -163,6 +165,22 @@ public class RuleIndexingControllerTest {
|
|||||||
new RuleIndexRange(900, 945));
|
new RuleIndexRange(900, 945));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyIndexingFileIsCorrupt() throws IOException {
|
||||||
|
byte[] stringBytes =
|
||||||
|
getBytes(
|
||||||
|
getKeyValueString(START_INDEXING_KEY, 100)
|
||||||
|
+ getKeyValueString("ccc", 200)
|
||||||
|
+ getKeyValueString(END_INDEXING_KEY, 300)
|
||||||
|
+ getKeyValueString(END_INDEXING_KEY, 900));
|
||||||
|
ByteBuffer rule = ByteBuffer.allocate(stringBytes.length);
|
||||||
|
rule.put(stringBytes);
|
||||||
|
InputStream inputStream = new ByteArrayInputStream(rule.array());
|
||||||
|
|
||||||
|
assertThrows(IllegalStateException.class,
|
||||||
|
() -> new RuleIndexingController(inputStream));
|
||||||
|
}
|
||||||
|
|
||||||
private static InputStream obtainDefaultIndexingMapForTest() {
|
private static InputStream obtainDefaultIndexingMapForTest() {
|
||||||
byte[] stringBytes =
|
byte[] stringBytes =
|
||||||
getBytes(
|
getBytes(
|
||||||
|
|||||||
Reference in New Issue
Block a user