-
Notifications
You must be signed in to change notification settings - Fork 236
bugfix(replay): Validate next frame value in RecorderClass::readNextFrame for replay playback #3090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1277,8 +1277,19 @@ AsciiString RecorderClass::readAsciiString() { | |
| */ | ||
| void RecorderClass::readNextFrame() { | ||
| Int bytesRead = m_file->read(&m_nextFrame, sizeof(m_nextFrame)); | ||
| if (bytesRead != sizeof(m_nextFrame)) { | ||
| DEBUG_LOG(("RecorderClass::readNextFrame - read failed on frame %d", TheGameLogic->getFrame())); | ||
|
|
||
| // TheSuperHackers @bugfix Check whether the next frame value is within a reasonable range | ||
| // to avoid prolonging playback due to potentially corrupted data. | ||
| const Bool validFrameValue = (m_mode == RECORDERMODETYPE_NONE | ||
|
Caball009 marked this conversation as resolved.
|
||
| || (m_nextFrame >= TheGameLogic->getFrame() && m_nextFrame < TheGameLogic->getFrame() + 3600 * LOGICFRAMES_PER_SECOND)); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can lower the maximum if one hour is too extreme. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open for discussion:
Based on the above, my suggestion would be somewhere between 1 and 10 minutes. Alternatively - and maybe the better option. Create a parameter in options.ini that sets it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a way to make this more robust would be to also read the next message in advance if the next frame is far away and see if that reads correctly or fails. This then gives higher confidence that the message is broken.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see a couple of complications with that:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having validate methods for all messages would perhaps be a nice thing to have in general. Validate all their bounds, and if they fail validation, then reject them. Right now we hope that the various message handlers deal with validation. But they probably do not sufficiently and there are holes.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be a nice thing, but not something I intend to do at this point. I'd rather close this PR and focus on other work if that's the desired change. |
||
|
|
||
| if (bytesRead != sizeof(m_nextFrame) || !validFrameValue) { | ||
| if (bytesRead != sizeof(m_nextFrame)) { | ||
| DEBUG_LOG(("RecorderClass::readNextFrame - read failed on frame %d", TheGameLogic->getFrame())); | ||
| } else { | ||
| DEBUG_CRASH(("RecorderClass::readNextFrame - current frame %d, next frame %d in the replay appears invalid", | ||
| TheGameLogic->getFrame(), m_nextFrame)); | ||
| } | ||
| m_nextFrame = -1; | ||
| stopPlayback(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_modeisn't updated yet when this called for the first time.