Sanity check

The theoretical chances of this happening are low. The compiler should complain that you're trying to put >int32.MaxValue in, but a check is totally fine.
This commit is contained in:
Morgan Gangwere 2016-07-15 17:07:08 -07:00
parent 9d0f6c385a
commit 73c830bde9
1 changed files with 6 additions and 0 deletions

View File

@ -55,6 +55,12 @@ namespace Kaitai
///<summary>Read N bytes from the stream.</summary>
public byte[] readBytes(int n)
{
if (n > Int32.MaxValue)
{
throw new ArgumentException(String.Format("Cannot allocate {0} bytes", n));
}
try
{
byte[] tmp = new byte[n];