rewind: fix zero-size savestates, and maybe fix a possible 1 byte array overrun

This commit is contained in:
zeromus 2017-04-17 22:42:42 -05:00
parent d7b0043379
commit c4776a0c00
1 changed files with 8 additions and 2 deletions

View File

@ -241,15 +241,21 @@ namespace BizHawk.Client.Common
goto CaptureFullState; goto CaptureFullState;
} }
if(currentState.Length == 0)
{
//handle empty states as a "full" (empty) state
goto CaptureFullState;
}
int index = 0; int index = 0;
int stateLength = Math.Min(currentState.Length, _lastState.Length); int stateLength = Math.Min(currentState.Length, _lastState.Length);
bool inChangeSequence = false; bool inChangeSequence = false;
int changeSequenceStartOffset = 0; int changeSequenceStartOffset = 0;
int lastChangeSequenceStartOffset = 0; int lastChangeSequenceStartOffset = 0;
if (_deltaBuffer.Length < stateLength) if (_deltaBuffer.Length < stateLength + 1)
{ {
_deltaBuffer = new byte[stateLength]; _deltaBuffer = new byte[stateLength + 1];
} }
_deltaBuffer[index++] = 0; // Full state = false (i.e. delta) _deltaBuffer[index++] = 0; // Full state = false (i.e. delta)