fix(json2): release partial copies on allocation failure #6593
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6593"
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 Ondra97 on 2026-10-15T21:49:31Z.
What
Release partially constructed
libSceJson2values and deep copies when an allocation fails. Construction keeps a temporary value until initialization succeeds; partial arrays, objects, nodes and append copies use the existing cleanup helpers before rethrowing.guest_json_copy_failuresweeps every allocation failure point across 17 construction, copy, assignment, setter and append cases. It checks allocation balance, unchanged sources and preservation of existing destinations. It compiles the productionExport.cppdirectly into the executable so its replacementoperator newcan inject failures.The review fix isolates this test from AnyPS5
libcon Linux. The injected failure previously also reached the guest unwinder:FindFrameFastallocates a cache-map node while holding its mutex, and a second injected exception reenters that mutex. A debugger backtrace reproduced this deadlock with GCC 13.3 and the CI linker, Wild 0.10.0. The isolated test uses the host C++ exception runtime; its unused unimplemented-export hook fails immediately if reached. Windows retains its existinglibcdependency and DWARF unwind setup for theAPS5_VABIframes. The shared-libraryguest_jsontest continues to exercise the production library.Tested
Base:
7a36de66b91217fb00fe6751343506ab01e677b3. Submitted revision:59dbdd615a3aa967e010e5d1c86f0ac7fef7de10. Review-fix commit:9ee4af350e0e928440745c11dcfb8c3bb17b7802.BUILD_TESTING=ON. GPU execution was not exercised.libc, Linux GCC 13.3/WildFindFrameFastmutex acquisitionvalue object copy budget=1, one retained allocationFinal focused runs: Windows 3/3, Linux GCC 13.3 2/2, and Linux GCC 16.0.1 1/1, with no failures or skips. The GCC 16 test also passed in a separate
-O0build. The original unwinder deadlock also reproduced with the available GCC 16.0.1 runtime. The 30-second CTest timeout and allocation sweep remain unchanged. Conventions, whitespace, main-sync and test-registration checks passed.Windows commands, after configuring with the supported toolchain:
Linux GCC 13.3 built
guest_json_testsandguest_json_copy_failure_tests, including their production-library dependencies, then ranctest -R '^guest_json(_copy_failure)?$' -V --output-on-failure --no-tests=error. The separate GCC 16 build compiled and ranguest_json_copy_failure_teststhrough CMake/CTest.These are host C++ allocation-failure regressions, not retail-title or system-wide OOM measurements. A new hosted CI run and the exact reported Arch GCC 16.2.1 toolchain have not been tested. Full Linux build, native Linux and GPU execution: not tested. The former build dependency #6452 is merged and no longer required as an open dependency.
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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T22:07:17Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceJson2/CMakeLists.txtcore/libs/prx/libSceJson2/CMakeLists.txtcore/libs/prx/libSceJson2/Export.cppcore/libs/prx/libSceJson2/Export.cppImported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-16T08:52:56Z.
Tested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON,mainat5d9dcc42d2ec5401aebd089028b8d4d7410a77b4.guest_json_copy_failure(this PR's test) aborts onmainplus this PR (2 of 2), and also on the PR head as submitted. It prints nothing:Under gdb the abort is raised inside the unwinder, not in a
Require:So the injected
std::bad_allocthrown by the replacementoperator new(JsonCopyFailure.cpp:55-62) seems not to reach thecatch (const std::bad_alloc&)atJsonCopyFailure.cpp:125when it passes through the cleanup path ofValue::Value(const Value&)(Export.cpp:683). The description reports Ubuntu 24.04 with GCC 13.3 passing, so this may depend on the toolchain (GCC 16.2.1 here). It also aborts when I build the two sources by hand at-O0. I did not find the root cause.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T07:01:00Z.
Review: CHANGES_REQUESTED
The full Build's Linux job fails on this PR's new test, and
maindoes not have the failure:guest_json_copy_failurehits the 30 sTIMEOUTset incore/libs/prx/libSceJson2/CMakeLists.txt:23(run 39211061883, "293/729 Test #1076 ... Timeout 30.05 sec")._Unwind_Resume(fromValue::Value(const Value&)) on GCC 16.2.1, so it fails on more than one toolchain: the injectedstd::bad_allocfrom the replacementoperator new(JsonCopyFailure.cpp:55-62) does not seem to reach thecatchatJsonCopyFailure.cpp:125when it unwinds through theAPS5_VABIexport frames.Please make the sweep terminate and pass on the CI Linux runner (and GCC 16), e.g. check that unwinding through the
APS5_VABIframes works there, or inject the failure at a point where it is catchable. TheExport.cppchanges themselves look right; the test is what needs to hold on Linux CI.Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-19T11:37:47Z.
@adriadam10 I pushed the test fix in
9ee4af350e, included in the current head59dbdd615a.I reproduced the timeout with GCC 13.3 and Wild 0.10.0. The replacement
operator newalso injected failures into AnyPS5libc:FindFrameFastallocates a cache-map entry while holding its mutex, and the resulting nested exception tries to acquire the same mutex. GDB confirmed that recursive lock acquisition.On Linux, the failure-injection test now uses the host C++ exception runtime without linking AnyPS5
libc. It still compiles the productionExport.cppand checks all 17 operations and 309 injected failures. Windows retains its existinglibcdependency and DWARF unwind setup. The 30-second timeout and sweep are unchanged. The base JSON implementation still fails the regression with one retained allocation.Validation at the current head:
-O0build passed too.The full hosted Linux/Windows jobs were skipped on this update. Could you rerun the full Linux CI job? @nicolasfalesy, could you retest with your Arch GCC 16.2.1? I have not verified that exact toolchain or independently reproduced its reported abort. The PR description contains the detailed results and commands.
AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-19T13:15:06Z.
Retested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON, head59dbdd615a3aa967e010e5d1c86f0ac7fef7de10.guest_json_copy_failure: passes, 2 of 2 (0.01 s each). The binary printsJSON copy cleanup: 17 operations, 309 allocation failures, no leaks.guest_json: passes, 2 of 2.-O0(JsonCopyFailure.cpp+Export.cpp, as in my earlier report): passes, 2 of 2, same output.The
_Unwind_Resumeabort from my earlier report is gone on this toolchain.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T14:16:37Z.
Re-checked after the test isolation (
9ee4af350): on Linuxguest_json_copy_failureno longer links AnyPS5libc, so the injectedbad_allocgoes through the host C++ unwinder instead of the guestFindFrameFastmutex that caused the 30 s timeout; Windows keepslibcand the DWARF unwind setup.Export.cppcleanup paths are unchanged from the earlier review and still correct. Merged.