--- a/asn.cpp
+++ b/asn.cpp
@@ -123,6 +123,8 @@ size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
- size_t bc;
- if (!BERLengthDecode(bt, bc))
- BERDecodeError();
-+ if (bc > bt.MaxRetrievable())
-+ BERDecodeError();
-
- str.New(bc);
- if (bc != bt.Get(str, bc))
+ size_t bc;\r
+ if (!BERLengthDecode(bt, bc))\r
+ BERDecodeError();\r
++ if (bc > bt.MaxRetrievable())\r
++ BERDecodeError();\r
+ \r
+ str.New(bc);\r
+ if (bc != bt.Get(str, bc))\r
@@ -139,6 +141,8 @@ size_t BERDecodeOctetString(BufferedTransformation &bt, BufferedTransformation &
- size_t bc;
- if (!BERLengthDecode(bt, bc))
- BERDecodeError();
-+ if (bc > bt.MaxRetrievable())
-+ BERDecodeError();
-
- bt.TransferTo(str, bc);
- return bc;
+ size_t bc;\r
+ if (!BERLengthDecode(bt, bc))\r
+ BERDecodeError();\r
++ if (bc > bt.MaxRetrievable())\r
++ BERDecodeError();\r
+ \r
+ bt.TransferTo(str, bc);\r
+ return bc;\r
@@ -161,6 +165,8 @@ size_t BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte as
- size_t bc;
- if (!BERLengthDecode(bt, bc))
- BERDecodeError();
-+ if (bc > bt.MaxRetrievable())
-+ BERDecodeError();
-
- SecByteBlock temp(bc);
- if (bc != bt.Get(temp, bc))
+ size_t bc;\r
+ if (!BERLengthDecode(bt, bc))\r
+ BERDecodeError();\r
++ if (bc > bt.MaxRetrievable())\r
++ BERDecodeError();\r
+ \r
+ SecByteBlock temp(bc);\r
+ if (bc != bt.Get(temp, bc))\r
@@ -188,6 +194,10 @@ size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigne
- size_t bc;
- if (!BERLengthDecode(bt, bc))
- BERDecodeError();
-+ if (bc == 0)
-+ BERDecodeError();
-+ if (bc > bt.MaxRetrievable())
-+ BERDecodeError();
-
- byte unused;
- if (!bt.Get(unused))
+ size_t bc;\r
+ if (!BERLengthDecode(bt, bc))\r
+ BERDecodeError();\r
++ if (bc == 0)\r
++ BERDecodeError();\r
++ if (bc > bt.MaxRetrievable())\r
++ BERDecodeError();\r
+ \r
+ byte unused;\r
+ if (!bt.Get(unused))\r
diff --git a/asn.h b/asn.h
index ed9de52..33f0dd0 100644
--- a/asn.h
+++ b/asn.h
@@ -498,6 +498,8 @@ void BERDecodeUnsigned(BufferedTransformation &in, T &w, byte asnTag = INTEGER,
- bool definite = BERLengthDecode(in, bc);
- if (!definite)
- BERDecodeError();
-+ if (bc > in.MaxRetrievable())
-+ BERDecodeError();
-
- SecByteBlock buf(bc);
-
+ bool definite = BERLengthDecode(in, bc);\r
+ if (!definite)\r
+ BERDecodeError();\r
++ if (bc > in.MaxRetrievable())\r
++ BERDecodeError();\r
+ \r
+ SecByteBlock buf(bc);\r
+ \r
--
2.10.2