8168705: Better ObjectIdentifier validation
authorascarpino
Thu, 17 Nov 2016 09:51:10 -0800
changeset 43216 c0f498d6a804
parent 43215 f3d46da34ae9
child 43217 d935c4d3f039
8168705: Better ObjectIdentifier validation Reviewed-by: mullan, asmotrak, ahgross
jdk/src/java.base/share/classes/sun/security/util/ObjectIdentifier.java
--- a/jdk/src/java.base/share/classes/sun/security/util/ObjectIdentifier.java	Thu Nov 17 16:59:18 2016 +0000
+++ b/jdk/src/java.base/share/classes/sun/security/util/ObjectIdentifier.java	Thu Nov 17 09:51:10 2016 -0800
@@ -255,7 +255,13 @@
                 + " (tag = " +  type_id + ")"
                 );
 
-        encoding = new byte[in.getDefiniteLength()];
+        int len = in.getDefiniteLength();
+        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);
     }