diff --git a/scratchpad/HWPF/Model/UnhandledDataStructure.cs b/scratchpad/HWPF/Model/UnhandledDataStructure.cs index 017f69d41..033e791b7 100644 --- a/scratchpad/HWPF/Model/UnhandledDataStructure.cs +++ b/scratchpad/HWPF/Model/UnhandledDataStructure.cs @@ -25,13 +25,17 @@ public class UnhandledDataStructure public UnhandledDataStructure(byte[] buf, int offset, int length) { // Console.WriteLine("Yes, using my code"); - _buf = new byte[length]; if (offset + length > buf.Length) { throw new IndexOutOfRangeException("buffer length is " + buf.Length + "but code is trying to read " + length + " from offset " + offset); } - Array.Copy(buf, offset, _buf, 0, length); + if(offset < 0 || length < 0) + { + throw new IndexOutOfBoundsException("Offset and Length must both be >= 0, negative " + + "indicies are not permitted - code is tried to read " + length + " from offset " + offset); + } + _buf = Array.Copy(buf, offset, _buf, 0, length); } internal byte[] GetBuf()