[Data integrity] Fix save-memory metadata failures and setup recovery #1667
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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-08T16:03:07Z.
Split from #1659. Category: data integrity, starting with save-memory initialization and recovery after a failed metadata write.
Problem and user-visible consequence
sceSaveDataSetupSaveDataMemory2can return success after creating or growing the memory blob even when it failed to persist the requested initialSaveDataParam. The caller therefore receives a successful setup result for an incomplete saved state.A return-code fix alone is insufficient. The blob is committed first, and a later call with the same size can skip the initialization branch because that blob now exists. Recovery must be designed so the failed attempt does not permanently bypass the requested initialization or destroy an older valid save.
Evidence and affected code
Baseline checked: upstream
4b005b229e24be9ec3f185def9e59cbc03aa9e4a.setupSaveDataMemory2, lines 611–650 enters initialization when the blob is missing or smaller thanmemory_size.SAVE_DATA_ERROR_INTERNALon failure.init_param != nullptrand option bit 1 is set, the parameter replacement at line 643 ignores its boolean result. Execution continues to initialize the result structure and returnSAVE_DATA_OK.SaveDataFile.hppwrites to a.tmppath, checks stream operations, and replaces the destination. Its failure result is available; this setup caller drops it.The review reproduced a success return with the blob present and the parameter file absent on checkout
34d4cf1796054a31feb7ced250bea8cbb8f66058. The unchecked setup call remains at the upstream baseline above. This was a synthetic filesystem test, not a claim of observed game-save loss.Deterministic reproduction
Use an isolated temporary working directory and the native save-data library:
sceSaveDataInitialize3._sd_mem/u42/slot0.param.tmp; opening that path as a metadata output file must fail.SaveDataParamwith a recognizableuser_paramvalue.SaveDataMemorySetup2withuser_id=42,slot_id=0,memory_size=128,option=1, andinit_parampointing to that parameter structure.sceSaveDataSetupSaveDataMemory2, recording its return code and result fields._sd_mem/u42/slot0.binand_sd_mem/u42/slot0.param.The current first call can return zero while only the blob exists. The retry needs explicit verification because an already-created 128-byte blob no longer satisfies the initialization condition. The replacement helper may remove the empty temporary directory itself; tests must tolerate that cleanup and recreate the obstruction for independent cases.
Required behavior and design decisions
Atomic rollback is one possible implementation; a clearly defined recoverable intermediate state may be another if supported by the intended API contract. Choose the smallest correct approach and verify it. Do not promise resilience to sudden power loss without testing/documenting the required persistence guarantees.
Test matrix
init_param == nullptror initialization option disabledUse deterministic failures such as the temporary-path obstruction instead of relying solely on permissions that behave differently for privileged runners. Add replacement/write failure injection only where existing helpers support it or a concrete missing case requires it.
Existing coverage and related work
Build on
SaveDataMemoryMetadata.cpp,SaveDataMemoryGrowth.cpp, and the registered replacement/failure tests incore/libs/CMakeLists.txt.#312 already covers metadata failure in the set-memory path. #244 and #1109 improve replacement/write failure handling. Retain those fixes; extend coverage for setup and its retry state rather than duplicating existing tests.
Acceptance criteria
Related category issues