Going beyond the range of the array!

Sep 7, 2010 at 9:11 AM

Are you concerned about this code? 

Line 410:

int srcLength = srcBytes.Length;
/* ..... */
Buffer.BlockCopy(srcBytes, 0, dstBytes, dst, srcLength);
if (dstLength - srcLength > 0)
{
	// Need to clear?
	if (dstBytes[dst + srcLength + 1] != 0)
	{
		Array.Clear(dstBytes, dst + srcLength, dstLength - srcLength);
	}
}

That is, on the fact we get out beyond the array.

Fixed:

Buffer.BlockCopy(srcBytes, 0, dstBytes, dst, srcLength);
if (dstLength - srcLength > 0)
{
	// Need to clear?
	if (dst + srcLength < dstBytes.Length && dstBytes[dst + srcLength] != 0)
	{
		Array.Clear(dstBytes, dst + srcLength, dstLength - srcLength);
	}
}