Handle atomic formula max value size
Bug: 143697198
Test: atest FrameworksServicesTests:RuleBinaryParserTest
Test: atest FrameworksServicesTests:RuleBinarySerializerTest
Change-Id: I6455e0c3a9964cec7618cd666bcda7599e92668e
diff --git a/services/core/java/com/android/server/integrity/model/BitOutputStream.java b/services/core/java/com/android/server/integrity/model/BitOutputStream.java
index ecb9189..b8ea041 100644
--- a/services/core/java/com/android/server/integrity/model/BitOutputStream.java
+++ b/services/core/java/com/android/server/integrity/model/BitOutputStream.java
@@ -42,7 +42,7 @@
int offset = 1 << (numOfBits - 1);
while (numOfBits-- > 0) {
mBitSet.set(mIndex, (value & offset) != 0);
- offset >>= 1;
+ offset >>>= 1;
mIndex++;
}
}
diff --git a/services/core/java/com/android/server/integrity/model/ComponentBitSize.java b/services/core/java/com/android/server/integrity/model/ComponentBitSize.java
index d47ce2d..6ec2d5f 100644
--- a/services/core/java/com/android/server/integrity/model/ComponentBitSize.java
+++ b/services/core/java/com/android/server/integrity/model/ComponentBitSize.java
@@ -29,7 +29,7 @@
public static final int OPERATOR_BITS = 3;
public static final int CONNECTOR_BITS = 2;
public static final int SEPARATOR_BITS = 2;
- public static final int VALUE_SIZE_BITS = 5;
+ public static final int VALUE_SIZE_BITS = 6;
public static final int IS_HASHED_BITS = 1;
public static final int ATOMIC_FORMULA_START = 0;
diff --git a/services/core/java/com/android/server/integrity/serializer/RuleBinarySerializer.java b/services/core/java/com/android/server/integrity/serializer/RuleBinarySerializer.java
index cb83765..25defb0 100644
--- a/services/core/java/com/android/server/integrity/serializer/RuleBinarySerializer.java
+++ b/services/core/java/com/android/server/integrity/serializer/RuleBinarySerializer.java
@@ -179,6 +179,9 @@
private void serializeStringValue(
String value, boolean isHashedValue, BitOutputStream bitOutputStream) {
+ if (value == null) {
+ throw new IllegalArgumentException("String value can not be null.");
+ }
byte[] valueBytes = getBytesForString(value, isHashedValue);
bitOutputStream.setNext(isHashedValue);
diff --git a/services/tests/servicestests/src/com/android/server/integrity/parser/RuleBinaryParserTest.java b/services/tests/servicestests/src/com/android/server/integrity/parser/RuleBinaryParserTest.java
index 86778f5..9cc0ed8 100644
--- a/services/tests/servicestests/src/com/android/server/integrity/parser/RuleBinaryParserTest.java
+++ b/services/tests/servicestests/src/com/android/server/integrity/parser/RuleBinaryParserTest.java
@@ -305,7 +305,7 @@
@Test
public void testBinaryString_validAtomicFormula_hashedValue() throws Exception {
- String appCertificate = "test_cert";
+ String appCertificate = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
String ruleBits =
START_BIT
+ ATOMIC_FORMULA_START_BITS
diff --git a/services/tests/servicestests/src/com/android/server/integrity/serializer/RuleBinarySerializerTest.java b/services/tests/servicestests/src/com/android/server/integrity/serializer/RuleBinarySerializerTest.java
index 3c78c37..981db6a 100644
--- a/services/tests/servicestests/src/com/android/server/integrity/serializer/RuleBinarySerializerTest.java
+++ b/services/tests/servicestests/src/com/android/server/integrity/serializer/RuleBinarySerializerTest.java
@@ -334,7 +334,7 @@
@Test
public void testBinaryString_serializeValidAtomicFormula_hashedValue() throws Exception {
- String appCertificate = "test_cert";
+ String appCertificate = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
Rule rule =
new Rule(
new AtomicFormula.StringAtomicFormula(