fix(json2): release partial entries on allocation failure #8530
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8530"
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-20T15:17:29Z.
What
Json2 array parsing constructs each value before linking it into its owning list. If list-node allocation fails, destination cleanup cannot reclaim that value. On the tested base, parsing
[1]with allocation budget 2 retains one allocation after cleanup.Construct each array entry directly in its owning list so existing partial-tree cleanup owns it before further allocation. The base already handles the object-entry failure paths from the original patch; retain its ordered object insertion, duplicate-key replacement and incremental parser behavior.
Extend allocation-failure coverage for valid and malformed documents, nested containers, long keys, callback reads and missing-key insertion. Preserve upstream iterator-copy and swap regressions. Check destination values, entry identity, container sizes and mismatch handlers after failures. Related to #8005, finding C9; no title, OOM or performance improvement is claimed.
The agreed order with #10378 is #8530 first, then #10378 rebased onto it; #10378 already declares
Depends on: #8530. That branch replaces the same parser loop with allocator-backed storage and has added bounded[1]/[1,failure and callback-reader coverage. Its later rebase must preserve the cleanup invariant, allocator behavior and measured partial-parser states. The old list edit and host-allocation budget counts are not copied verbatim. No combined build of the two open PRs is claimed.Tested
Rebased on upstream
main2e22b67032ea335ecad88b1acf777a29a70d851b; tested PR head3e54ab2633b6b8ccc0c6b82d286dc3aa4e09948b. Windows 11 Pro 10.0.26300, Ryzen 9 7900X, 31.7 GiB RAM, NVIDIA GeForce RTX 4070 Ti SUPER, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Ninja, Release,BUILD_TESTING=ON, pinned bundled dependencies. These Json2 tests use the CPU.cmake --build <build> --target relinker libs guest_json_tests guest_json_copy_failure_tests patched_libraries_tests --parallel 8: production relinker, all patched libraries and selected Json2 fixtures built successfully.ctest --test-dir <build> -R '^(guest_json|guest_json_numeric_locale|guest_json_copy_failure|patched_libraries)$' -V --output-on-failure --no-tests=error: 4/4 passed, zero skips; 368 patched libraries loaded, none failed. The allocation regression performed 37 operations and 549 forced allocation failures without a tracked leak, including[1], malformed/nested input, callback reads, long keys, object insertion, iterator copies and swap.ctest --test-dir <build> -R '^public_headers($|_compile_)' -j 8 --output-on-failure --no-tests=error: 65/65 passed, zero skips, including the audit and all 64 header compilation batches.JsonCopyFailure.cppnow uses the publicApi.hpptypes and declarations introduced by #10706; its mismatch callback uses the declaredValueTypeABI. No duplicate PS5 export prototypes remain in the test.python tools/check_conventions.py --base origin/main,python tools/check_main_sync.py --base origin/main --strict,git diff origin/main...HEAD --checkandpython tools/check_test_registration.py <build>: passed.python tools/pr_overlap.py --branch codex/pr8530-rebase-20261025 --repo boykopovar/AnyPS5 --jobs 12completed; #10378 is the agreed follow-up and changes the same parser loop, while #9826 covers separate placeholders.The historical pre-fix control failed at
parse array budget=2: operation leaked allocations. This rebase did not repeat that negative control on current main; its parser still constructs the item before list admission. The default all-target build, complete CTest suite and title run were not performed on this rebased head.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 Ondra97 on 2026-10-20T16:52:51Z.
Could someone help establish the PS5 Json2 allocator/initialization contract for the separate C2 follow-up in #8005? This is a contract question for that follow-up; the implementation in this PR covers allocation-failure ownership.
On tested revision c9f680fb, a synthetic parse/serialize probe performs 21 tracked host C++ allocations and makes zero calls to the supplied allocator's allocate/free/notify callbacks. Both the normal and null-returning callback settings still give successful initialize/parse results. Since no callback runs, this confirms ignored configuration but does not validate the candidate callback ABI.
I need to establish:
fileBufferSize, including what a zero size means.SpecialFloatFormatTypevalues and their behavior, especially value2in the supplied initialization configuration.An API reference or results from a small PS5 test covering these cases would help me implement the general behavior and add a regression that fails before the fix and passes afterward. The synthetic probe uses no title assets.
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:50:11Z.
Review: APPROVED
Checked against main
522e32e3b6and libSceJson2 Export.cpp on main:Nodebeforepush_back, so a failure on the list-node allocation leaks it;[1]at budget 2 is a concrete case.emplace_back()leavesnode == nullptruntilConstructsucceeds, andDestroy(Value)skips null nodes, soParseValue'sClearnow reclaims every partial entry. I found no double-free or dangling reference.ObjectEntry,Array::push_back, the object iterator insert) already roll back on failure, so this was the remaining gap. The test's expected codes (-1 from the reader, 0x80848101 otherwise) match main'sParser::Error.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.