fix(savedata): preserve memory on write failure #1109
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1109"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Sanjaysrinivas on 2026-10-07T12:44:37Z.
What
Native
sceSaveDataSetSaveDataMemory2writes each range directly into the existing.binsave. A later I/O failure returnsSAVE_DATA_ERROR_INTERNALafter earlier bytes have already changed. Reproduced with two valid updates to a 32-byte save under a 16-byte file-size limit: the call fails and the original save is changed.Read the existing blob, apply the already-validated ranges in memory, and reuse
write_file_replace. That helper is already used by native save setup and metadata persistence, and only replaces the original after a complete temporary-file write, flush and close. Verify the loaded size still matches the size used to validate the ranges.Extend the existing memory regression to check temporary-file creation failure, partial write failure on POSIX, invalid later ranges, binary payloads, untouched bytes, zero-sized ranges, and the existing
data_num == 0single-entry convention. No new dependency, abstraction or test target.This copies and writes the complete memory blob per update (setup permits at most 16 MiB). The change protects the
.binupdate;.binand.paramremain separate replacements, and this does not add power-loss durability beyond the existing replacement helper.Tested
Earlier focused validation of the unchanged contribution patch:
Ubuntu 24.04 under WSL2, GCC 13.3.0, x86-64; synthetic saves, no game files:
original save preserved.SaveDataMemoryMetadatafails when a blocked temporary path should prevent updating the original save.savedata_memory_metadata,savedata_memory_growth,savedata_memory_growth_read_failure,guest_savedata_delete,guest_savedata_ps4,mspace, andguest_reallocalign.-Wall -Wextra -Werror.git diff --checkpasses.With the full repository configured and built with
BUILD_TESTING=ON:Local validation harnesses and investigation notes are excluded from this patch. Full-build results and remaining platform limits are recorded below.
PR overlap (earlier checks)
Direct per-file three-way merge checks confirm a conflict with the whole-tree formatting PR #1128 in
core/libs/tests/SaveDataMemoryMetadata.cpp. That PR does not implement this bug fix. #1128 currently conflicts with upstream inStdioExtras.cpp, so the repository overlap tool skips its pairwise conflict check; its empty result does not clear this overlap. This PR merges cleanly into upstream1e5bb880; merging it and #1128 will require rebasing whichever lands second.Earlier local validation after rebase
Rebased onto upstream
mainatcea1ef13. Tested head:b00dd85c2050bc0e04b00befdc31d17d516d6241.Ubuntu 24.04 under WSL2, GCC 13.3, Release; the contribution patch is preserved and its tree matches the checked merge result.
git diff --checkpassed.BUILD_TESTING=ON.Title/homebrew execution remains untested. The GitHub-hosted fork checks below are separate from these local results.
Independent fork CI
Build run 37676598080 passed on exact PR head
c4cfb8e23d92d8fcdfb721d87093999288a0db48.Rebased onto upstream
mainat4764e59c37b1fc6c89284fdecaef5a5718b6119e. The unchanged contribution's source tree matches the checked automatic merge result; conventions andgit diff --checkpassed.Both jobs completed the full Release CMake build with
BUILD_TESTING=ON, thelibstarget and the full CTest suite with--timeout 120 --repeat until-fail:3.guest_force_tls_destructorregression passed in all three Linux repetitions.These fork checks do not replace upstream workflow approval or maintainer review. No title/homebrew execution or RDNA hardware measurement is claimed.
Checklist
mainat4764e59c; no other open PR implements the same fix