public void Corruption() { var source = new byte[1234]; Lorem.Fill(source, 0, source.Length); var array = LZ4Pickler.Pickle(source); var copy = array.AsSpan().ToArray(); var output = source.AsSpan().ToArray(); // pass a buffer that's too short Assert.Throws <InvalidDataException>(() => LZ4Pickler.Unpickle(array.AsSpan().Slice(0, 2), output)); Assert.Throws <InvalidDataException>(() => LZ4Pickler.UnpickledSize(array.AsSpan().Slice(0, 2))); // corrupt the version array[0] = 0xff; Assert.Throws <InvalidDataException>(() => LZ4Pickler.Unpickle(array, output)); Assert.Throws <InvalidDataException>(() => _ = LZ4Pickler.UnpickledSize(array)); // corrupt the size array[0] = copy[0]; array[1] = 0xff; Assert.Throws <InvalidDataException>(() => LZ4Pickler.Unpickle(array, output)); }