File tree Expand file tree Collapse file tree
com.unity.netcode.gameobjects/Tests/Editor/Serialization Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) ]
You can’t perform that action at this time.
0 commit comments