Skip to content

Commit 4aed486

Browse files
test
Updating test to unsafely read a string under the same condition.
1 parent 41660e8 commit 4aed486

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

com.unity.netcode.gameobjects/Tests/Editor/Serialization/FastBufferReaderTests.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ public void GivenFastBufferWriterContainingValue_WhenReadingString_ValueMatchesW
933933
/// into restricted memory and causes the editor to crash.
934934
/// </summary>
935935
[Test]
936-
public void ReadingStringAfterStringLengthHasAlreadyBeenRead()
936+
public void ReadingStringAfterStringLengthHasAlreadyBeenRead([Values] bool isSafeRead)
937937
{
938938
// This was an issue uncovered in UUM-145752 that resulted
939939
// in the below text to result in a length that when using
@@ -954,9 +954,19 @@ public void ReadingStringAfterStringLengthHasAlreadyBeenRead()
954954
// the string reader reads the some of the bytes for the actual text as the length.
955955
reader.ReadByteSafe(out byte count);
956956
Assert.True(count == valueToTest.Length, $"Count ({count}) is not the expected size of {valueToTest.Length}!");
957+
if (isSafeRead)
958+
{
959+
// This should throw an overflow exception but should not crash the editor.
960+
Assert.Throws<OverflowException>(() => reader.ReadValueSafe(out string valueRead));
961+
}
962+
else
963+
{
964+
// Assume user does a pre-calculation of the size to be read:
965+
Assert.IsTrue(reader.TryBeginRead(count), "Reader denied read permission");
957966

958-
// This should throw an overflow exception but should not crash the editor.
959-
Assert.Throws<OverflowException>(() => reader.ReadValueSafe(out string valueRead));
967+
// This should throw an overflow exception but should not crash the editor.
968+
Assert.Throws<OverflowException>(() => reader.ReadValue(out string valueRead));
969+
}
960970
}
961971

962972
[TestCase(1, 0)]

0 commit comments

Comments
 (0)