GSF.IO.BinaryStreamBase.TryReadBytes C# (CSharp) Method

TryReadBytes() public method

Reads a byte array from the provided stream. If the size of the stream exceedes maxLength value is set to null and this function returns false.
This method can be used to limit the byte size returned. Since an untrusted source could claim that the length is int.MaxValue, this prevents allocating 2GB of RAM to store the result.
public TryReadBytes ( int maxLength, byte &value ) : bool
maxLength int
value byte
return bool
        public bool TryReadBytes(int maxLength, out byte[] value)
        {
            int length = (int)Read7BitUInt32();
            if (length < 0 || length > maxLength)
            {
                value = null;
                return false;
            }
            value = ReadBytes(length);
            return true;
        }