fix(savedata): read every sceSaveDataSetSaveDataMemory2 data entry at its 64-byte stride #5659
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5659"
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 wachi35676 on 2026-10-14T04:56:02Z.
What
SaveDataMemoryDataincore/libs/SceTypes.hppwas declared as 24 bytes (buf,buf_size,offset).sceSaveDataSetSaveDataMemory2in libSceSaveData.native indexes the guest'sdataarray with that stride (Export.cpp, theset_param->data[i]loops), so with 64-byte guest entries it read entry 1 from the reserved bytes of entry 0, saw a zero size, skipped it, and returnedSAVE_DATA_OKwith only the first range written.The entry is 64 bytes (buffer, size, offset, 40 reserved bytes), as the sibling library already declares and asserts:
core/libs/prx/libSceSaveData/SaveDataCore.hppstatic_assert(sizeof(MemoryData) == 64, "SceSaveDataMemoryData is 64 bytes"). shadPS4'sOrbisSaveDataMemoryDatahas the same layout. This adds the reserved bytes and astatic_assert. Only the Set path indexes the array; the Get path reads a single entry.With the shared type the right size,
SaveDataCore.hppno longer needs its privateMemoryDatacopy: it now usesSaveDataMemoryDataand drops the threereinterpret_casts toMemoryData. Itsvalid_memory_rangetakes the shared type's unsigned offset; a negative guest offset is still rejected, because as an unsigned value it exceeds any memory size. The old and new checks agree on 40,000,000 edge and random (buffer, size, offset) cases for every memory size below 2^63 bytes.savedata_memory_metadatagets a block that lays out two entries by hand at a 64-byte stride and checks both ranges reach the save. The existing 3-entry case is unchanged.Tested
Windows 11 26200, WinLibs GCC 15.2.0 UCRT, full build with
BUILD_TESTING=ONonmain75690a117.savedata_memory_metadatafails (Save-data memory check failed at line 138, the file-content check; the call itself returned 0).main2582ec119: all 13 save data tests pass (savedata_*andguest_savedata_*, both libraries).python tools/check_conventions.py --base origin/mainpasses.Not tested: Linux and macOS builds; titles (no title ID known to call
sceSaveDataSetSaveDataMemory2with more than one entry).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-14T06:06:46Z.
The fix is right: libSceSaveData.native indexes set_param->data[i], so a 24-byte struct read entries 2+ from the first entry's reserved bytes.
The same guest struct now exists twice: SaveDataMemoryData in SceTypes.hpp and MemoryData in libSceSaveData/SaveDataCore.hpp (which already asserts 64). Both are asserted now, so they can't drift silently, but if one can include the other, a single definition would be cleaner.
Nice that the test builds the entries at a raw 64-byte stride instead of using the struct, so it would still catch a wrong struct size.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-14T09:00:59Z.
Thanks, good point. With
SaveDataMemoryDatanow 64 bytes,SaveDataCore.hppno longer needs its own copy, so I droppedMemoryDataand the threereinterpret_casts to it and it uses the shared type directly. The one difference was the offset type (std::int64_tthere,std::size_tinSceTypes.hpp):valid_memory_rangenow takes the unsigned offset, and a negative guest offset is still rejected because it exceeds any memory size. I compared the old and new checks on 40M edge and random cases with zero differences for every memory size below 2^63. All 13 save data tests pass on currentmain. Amended into the same commit and updated the description.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:43:23Z.
Checked on Linux: build + core/libs ctest 32/32 green;
savedata_memory_metadatafails without the header change and passes with it. The sharedSaveDataMemoryDatais now 64 bytes, matchinglibSceSaveData's old private copy, andlibSceSaveData.nativealready bounds-checks the offset as unsigned. Merging once the full Build is green.