1 files changed, 9 insertions, 8 deletions
diff --git a/crypto/src/tls/TlsUtilities.cs b/crypto/src/tls/TlsUtilities.cs
index 7a601bebf..d187aeed2 100644
--- a/crypto/src/tls/TlsUtilities.cs
+++ b/crypto/src/tls/TlsUtilities.cs
@@ -966,14 +966,15 @@ namespace Org.BouncyCastle.Tls
public static Asn1Object ReadAsn1Object(byte[] encoding)
{
- Asn1InputStream asn1 = new Asn1InputStream(encoding);
- Asn1Object result = asn1.ReadObject();
- if (null == result)
- throw new TlsFatalAlert(AlertDescription.decode_error);
- if (null != asn1.ReadObject())
- throw new TlsFatalAlert(AlertDescription.decode_error);
-
- return result;
+ using (var asn1In = new Asn1InputStream(encoding))
+ {
+ Asn1Object result = asn1In.ReadObject();
+ if (null == result)
+ throw new TlsFatalAlert(AlertDescription.decode_error);
+ if (asn1In.Length != asn1In.Position)
+ throw new TlsFatalAlert(AlertDescription.decode_error);
+ return result;
+ }
}
/// <exception cref="IOException"/>
|