289 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 0a687b9435 Savestate: Bounds-check sizes from the file, and plug leaks on load
Reject sizes past the end of the state before allocating (FPL, PGF,
achievements, SAS grain, savedata list, the memory fast path), fail
instead of desyncing on a SAS voice count mismatch, and free what old
states' paths and shrinking pointer containers dropped.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-09-28 09:34:06 -06:00
Henrik RydgårdandClaude Opus 5.5 84f64a9fdf Savedata: Don't free stale icon textures after a state load
The old icons stayed in PPGe's decimation list with kernel addresses from
before the load, and got freed out of whatever the loaded state had there.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-09-28 09:34:05 -06:00
Henrik RydgårdandClaude Opus 5.5 9e69c1f9aa Savedata: Keep the IO thread out of the dialog's state
Replaces the temporary fix that did the hidden modes' IO inside Update.

The IO thread read and wrote the dialog's request, display state and save
list, all shared with the emulator thread, which kept using them to draw the
dialog and reload the request from the game.

Now the IO thread works on its own copy of the request, its own SavedataParam
and directory names resolved up front, and shares nothing else with the
emulator thread but the (locked) file system, MemoryStick_FreeSpace's cached
use and sceChnnlsv's scratch buffer and kirk state, the last two now under
locks too. It still reads and writes the game's buffers directly, like a PSP's
utility threads and sceIoReadAsync do, so a savestate waits for it before it
saves or loads memory. Save
bookkeeping, the save indicator and display changes happen on the emulator
thread when the results are taken, and only the request fields the IO changed
are copied back, so a game's own edits in the meantime survive.

Hidden modes take the results at the next Update (or, with Host IO timing,
the first Update that finds them done). The visible dialogs keep drawing and
take them once the IO is done; save and load used to stall the emulator
thread for the whole operation. Savestates keep results that haven't been
taken yet.

When the results land in PSP memory doesn't matter to games, so
utility/savedata/filelist now only prints them once the utility has finished.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-09-25 12:50:39 -06:00
Henrik RydgårdandClaude Opus 5.5 5a23bb2d94 Savedata: Pick the crypt mode the way the firmware does
secureVersion and the key only matter for the full 1536-byte request; the
older sizes always save without a key. Otherwise SDK 2.07+ uses the new
keyed hash for versions 0 and 3, older SDKs the old keyed hash for 0 and
no key for 3, and version 2 is always the old keyed hash.

Versions 0, 2 and 3 all require a key, and are rejected with SAVE_PARAM
otherwise - including 0, which we used to save without a key. Matches the
SFO modes and save errors recorded in utility/savedata/secureversion; what
remains there is load strictness when secureVersion doesn't match the
file, which we keep lenient for older saves.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-09-23 19:25:24 -06:00
Henrik RydgårdandClaude Opus 5.5 74c5cbf503 Savedata: Leave GetSize's needed strings alone when nothing is needed
Matches hardware; moves utility/savedata/getsize to tests_good.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-09-23 19:25:24 -06:00
Artem Lytkin 4c749a31cf Savedata: use PARAM.SFO's time as the save date in the dialog
GetSaveInfo() took the date from whichever file the directory listing
returned first, so a save whose ICON0.PNG is older than the rest showed
the icon's date in the save/load dialog. The savedata manager already
uses PARAM.SFO's time. Use that here too, keeping the first file as the
fallback when there's no PARAM.SFO.
2026-09-19 17:17:55 +03:00
keycross 0c95caccea Avoid validating unused savedata name lists 2026-08-28 21:38:58 +09:00
Henrik Rydgård 68ec34ad54 Build and warning fixes 2026-08-03 19:11:07 +02:00
Henrik Rydgård 0eef5d0164 Use shared HasPathTraversal utility for savedata name validation
Replace the inline lambdas in the savedata dialog with the new
HasPathTraversal() helper in Core/Util/PathUtil.
2026-08-01 13:16:21 +02:00
Henrik Rydgård 779cae6232 Reject path traversal in savedata name fields
gameName/saveName/fileName and the saveNameList entries are
guest-controlled and get concatenated into host filesystem paths, so a
crafted request could escape the save directory with ../ sequences.

- PSPSaveDialog::Init rejects requests whose name fields contain a path
  separator ('/' or '\') or are bare dot components.
- SavedataParam::SetPspParam rejects saveNameList entries the same way.
2026-08-01 13:16:21 +02:00
Henrik Rydgård 5194382b7b Fix out-of-bounds reads in PARAM.SFO parser
ReadSFO dereferenced index table entries without checking the table fit
within the buffer, and GetDataOffset had no bounds checks at all (reading
attacker-controlled offsets and strcmp'ing without a terminator guard).

- Validate the index table fits entirely within the buffer in ReadSFO.
- Add a size parameter to GetDataOffset and validate the index table,
  key/data table positions, and key string termination before use.
2026-07-31 20:54:17 +02:00
Henrik Rydgård 133c36f145 Minor logging cleanup in savedata 2026-03-02 00:24:19 +01:00
Henrik Rydgård 3dc7aa4a65 Add workaround for the Silent Hill: Shattered Memories. Thanks fcrwr!
Fixes #13781
2026-02-23 15:19:03 +01:00
Henrik Rydgård dac2407a36 sceIo: Add support for microseconds in filetimes (not implemented in platforms yet) 2026-02-23 11:04:17 +01:00
Henrik Rydgård 40a5cd1509 Minor logging improvement, refresh gamescreen on deleted savedata 2026-02-19 16:05:00 +01:00
Henrik Rydgård 0dd77f896a A few more string length safety fixes in SavedataParam.cpp 2026-02-18 11:24:55 +01:00
Henrik Rydgård f97a3d09bd Savedata: Fix rare crash bug found in Google Play reports 2026-02-18 11:24:36 +01:00
Henrik Rydgård dad8df3860 More logspam reduction 2026-02-10 15:05:29 +01:00
Henrik Rydgård 4d07fd6176 Avoid writing 0-sized ICON1 or SND0
Presumably this should also apply to PIC1 and ICON0 but let's keep the
change minimal.

Fixes #20443
2026-02-10 09:11:05 +01:00
Henrik Rydgård 6c324c6782 Minor cleanup 2026-01-01 13:47:19 +01:00
Henrik Rydgård 5f7a937466 Rename ValidSize to ClampValidSizeAt 2025-12-30 20:31:07 +01:00
Henrik Rydgård f5a211884b Minor cleanups, comments
Comments and warnings
2025-12-30 20:31:06 +01:00
Henrik Rydgård 1c49ad7b29 Support screen rotation on iOS (unrestricted) 2025-10-22 15:13:21 +02:00
Henrik Rydgård 5751e202a5 Remove redundant .c_str() 2025-08-31 13:37:43 +02:00
Henrik Rydgård f410b7e6ea Show a tiny indicator in the top left of the screen when the game is saving or loading. 2025-07-10 15:11:59 +02:00
Henrik Rydgård ecff4d03ee Update the naming of functions called by SavedataParam::EncryptData. Thanks Linblow, and Nemo for the reminder 2025-04-23 16:49:04 +02:00
Henrik Rydgård 0ecd72416b Reduce overhead of logging further. 2025-03-25 23:09:11 +01:00
Henrik Rydgård f14075e650 PPGe/savedata: Add a bunch of safety checks for png images. Fixes Digimon save crash, see #20125. 2025-03-21 10:07:42 +01:00
Henrik Rydgård 5080e9660a Remove an outdated hidden setting (bSavedataUpgrade) 2025-02-18 11:03:29 -06:00
Henrik Rydgård b2b0ff1753 Consolidate error codes in ErrorCodes.h 2025-02-04 11:53:00 -06:00
Henrik Rydgård 5c7ca3f972 Delete some unused structs 2025-01-10 21:18:45 +01:00
Henrik Rydgård 770538dd46 SavedataParam: Sanity check, read from the correct list when logging files.
See #19795
2025-01-03 00:49:08 +01:00
Henrik Rydgård c91169e702 Restore removed <algorithm> includes.
Turns out these were needed after all. For some reason, on Windows and
Mac, <algorithm> gets auto-included by something else so I don't notice
when it's missing, and MSVC's include dependency tracker doesn't see it
either.
2024-12-19 09:53:07 +01:00
Henrik Rydgård 3e198c53b2 More include cleanup 2024-12-18 13:57:26 +01:00
Henrik Rydgård eccf23cf3b Cleanup after prev PR 2024-11-30 02:51:48 +01:00
Henrik Rydgård 7cc59dcda1 Savedata multiload: Do a directory listing so we can filter missing directories faster. 2024-11-30 02:44:01 +01:00
Henrik Rydgård 84154e837e Avoid running the initial savedata size scan except on games that need it. 2024-11-29 15:48:39 +01:00
Henrik Rydgård 7e194d15e2 For the free-space savedata scan, only scan relevant subdirectories. 2024-11-29 15:34:22 +01:00
Henrik Rydgård 2e85eb5128 More static code analysis fixes 2024-10-28 17:59:06 +01:00
Henrik Rydgård b10c4f7fae Crashfix, warning fix, cleanup 2024-10-22 14:15:47 +02:00
Henrik Rydgård 1a89c26dc0 Warning fixes 2024-10-03 18:19:11 +02:00
Henrik Rydgård 9b8f18298a Translation fixes, etc
Thanks @TotalCaesar659
2024-09-27 10:15:52 +02:00
Herman Semenov 3c66f149d3 [Common/Core/Windows] Removed excess check pointer before delete or free() 2024-09-17 11:34:42 +02:00
Henrik Rydgård c2a38181ad Alternate solution for ModNation Racers metadata overwrite (see #18430 comments) 2024-09-10 19:06:22 +02:00
Henrik Rydgård f18715bb7c Some renaming 2024-07-16 22:04:41 +02:00
Henrik Rydgård 4582ee692a More logging changes 2024-07-16 22:04:41 +02:00
Henrik Rydgård 70cb1104dc Kirk: Remove use of uninitialized stack as a random number source
This confused Valgrind and made me think we had another memory bug.

Turns out this is NOT the cause of #13781, which I still don't
understand.
2024-07-16 22:04:41 +02:00
Henrik Rydgård cde71fc2b3 Misc cleanup 2024-07-16 22:04:41 +02:00
Henrik Rydgård f8bf0bfbb5 Add some new logging to sceUtility to try to figure out the Silent Hill problem 2024-07-16 22:04:41 +02:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00