Merge "Port "Better ObjectIdentifier validation" change from openJdk8u121-b13"
diff --git a/ojluni/src/main/java/sun/security/util/ObjectIdentifier.java b/ojluni/src/main/java/sun/security/util/ObjectIdentifier.java
index 38d171a..58f26c3 100644
--- a/ojluni/src/main/java/sun/security/util/ObjectIdentifier.java
+++ b/ojluni/src/main/java/sun/security/util/ObjectIdentifier.java
@@ -255,7 +255,13 @@
+ " (tag = " + type_id + ")"
);
- encoding = new byte[in.getLength()];
+ int len = in.getLength();
+ if (len > in.available()) {
+ throw new IOException("ObjectIdentifier() -- length exceeds" +
+ "data available. Length: " + len + ", Available: " +
+ in.available());
+ }
+ encoding = new byte[len];
in.getBytes(encoding);
check(encoding);
}
@@ -354,6 +360,7 @@
* @return components in an int array, if all the components are less than
* Integer.MAX_VALUE. Otherwise, null.
*/
+ // Android-changed: s/private/public: Needed to keep sort order of RDN from prev impl
public int[] toIntArray() {
int length = encoding.length;
int[] result = new int[20];