summary refs log tree commit diff
path: root/crypto/src/asn1/DerInteger.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/DerInteger.cs')
-rw-r--r--crypto/src/asn1/DerInteger.cs13
1 files changed, 12 insertions, 1 deletions
diff --git a/crypto/src/asn1/DerInteger.cs b/crypto/src/asn1/DerInteger.cs
index 3610de588..5b240d281 100644
--- a/crypto/src/asn1/DerInteger.cs
+++ b/crypto/src/asn1/DerInteger.cs
@@ -70,7 +70,18 @@ namespace Org.BouncyCastle.Asn1
 		public DerInteger(
             byte[] bytes)
         {
-            this.bytes = bytes;
+            if (bytes.Length > 1)
+            {
+                if (bytes[0] == 0 && (bytes[1] & 0x80) == 0)
+                {
+                    throw new ArgumentException("malformed integer");
+                }
+                if (bytes[0] == (byte)0xff && (bytes[1] & 0x80) != 0)
+                {
+                    throw new ArgumentException("malformed integer");
+                }
+            }
+            this.bytes = Arrays.Clone(bytes);
         }
 
 		public BigInteger Value