2 files changed, 24 insertions, 2 deletions
diff --git a/crypto/src/asn1/DerEnumerated.cs b/crypto/src/asn1/DerEnumerated.cs
index 476b7fa9a..db27065bb 100644
--- a/crypto/src/asn1/DerEnumerated.cs
+++ b/crypto/src/asn1/DerEnumerated.cs
@@ -64,7 +64,18 @@ namespace Org.BouncyCastle.Asn1
public DerEnumerated(
byte[] bytes)
{
- this.bytes = bytes;
+ if (bytes.Length > 1)
+ {
+ if (bytes[0] == 0 && (bytes[1] & 0x80) == 0)
+ {
+ throw new ArgumentException("malformed enumerated");
+ }
+ if (bytes[0] == (byte)0xff && (bytes[1] & 0x80) != 0)
+ {
+ throw new ArgumentException("malformed enumerated");
+ }
+ }
+ this.bytes = Arrays.Clone(bytes);
}
public BigInteger Value
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
|