libretro: detect and communicate buffer overflow on save state serialization#2089
Merged
flyinghead merged 2 commits intoflyinghead:masterfrom Oct 21, 2025
Merged
Conversation
flyinghead
reviewed
Oct 20, 2025
core/serialize.h
Outdated
| public: | ||
| Exception(const char *msg) : std::runtime_error(msg) {} | ||
| }; | ||
|
|
Owner
There was a problem hiding this comment.
I would prefer to move the existing Deserializer::Exception to the base class SerializeBase so it can be used by both.
Contributor
Author
There was a problem hiding this comment.
Good call, just pushed that change.
flyinghead
reviewed
Oct 20, 2025
| std::vector<int> data(10); | ||
| Serializer ser(buffer.data(), buffer.size()); | ||
| ASSERT_THROW(ser.serialize(data.data(), data.size()), Serializer::Exception); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As discussed in Issue #1903, the libretro core uses dynamic sizing for save states. If the size requirements increase over time by the core, then the RetroArch front end will disregard it and only supply the initial lower size provided in
retro_serialize_size(). This creates a scenario where a buffer is passed toretro_serialize()that is not big enough to store all of the necessary data, and will result in a buffer overflow. In these cases, though it appears to succeed in creating the save state, the file itself is incomplete and cannot be successfully loaded. It's possible the overflow can cause other issues but I saw no evidence of this outside of the incomplete save state file.This PR aims to improve the situation by:
This does not fix the underlying issue, but correctly communicates to the front end and the user* that creating the save state failed.
*In testing, it looks like the current version of RA does not actually show an error to the user that a save state failed to save, though it does not say it was successful either like it did before. I plan on filing a PR to make this more visible on the RA front end as well.