fix(libSceNpUniversalDataSystem): copy record and event-property keys, strings and binary values through checked reads #23418
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23418"
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 milescoviello on 2026-11-19T01:28:04Z.
What
Folds my two open
libSceNpUniversalDataSystemguest-copy PRs into one, as asked on #23161. Each commit is the original PR's change with its message, and the two debt entries are merged into one fragment. #20812 and #20813 will be closed with a link here.Both originals were stacked on my #20678 (
CopyGuestStringgrows its buffer by page instead of allocating the cap up front), and so is this PR: its first commit is #20678's. The key and string copies below useSIZE_MAXas the cap, because the direct reads had no length limit, and that needs #20678.IntRecord*builders inRecord.cpp(#20812). Object keys,IntRecord*SetStringvalues and theIntCreateRecordDatarecord type are copied withCopyGuestString_nid_no_patch.IntRecord*SetBinarybytes are copied with oneGuestCopyIn_nid_no_patch.0x80553114, an unreadable record type0x8055310Dand an unreadable value0x80553115, the codes a null one returns. Nothing is stored.0x80553101, the file's out-of-memory code. Since192b3b8f8ftheIntRecord*SetBinarysetters also return it, and store nothing, when their buffer cannot be allocated (before it,std::bad_allocescaped).EventPropertyObjectSet*keys, theSetStringvalues and theSetBinarybytes go through the same copies. A newUds::CopyTexthelper returns0x80553101for a string too large for host memory, and theSetBinarysetters return it when their buffer cannot be allocated; nothing is stored (since96f1b07783; before it,std::bad_allocescaped, as thestd::stringconstruction it replaced did).SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_INVALID_KEY; an unreadable value or byte buffer returns..._NULL_VALUE.key = name.c_str(), assigaltstackdoes withstack), so theSetlines are unchanged.Valid calls behave as before, including very long keys and values, empty-key rejection and the check order. The debt fragment marks the error codes as host-safety fallbacks; console behaviour here is not measured.
Tested
Out-of-memory follow-ups (MarcZX10's reviews, 11-21), head
e1e4aaba03:96f1b07783: the event propertySetBinarysetters andUds::CopyText(event property keys and strings) return0x80553101and store nothing when the copy does not fit in host memory, instead of lettingstd::bad_allocout of the C API.192b3b8f8f:IntRecordArraySetBinaryandIntRecordObjectSetBinarydo the same before the guest copy.4e907ffa0f(the same commit as on #20678):CopyGuestString_nid_no_patchalso returns 12 forstd::length_errorfrom its resize or final assign. In practice that can't be thrown there: the buffer grows a page at a time and the copy stops at the first unreadable page.10f4a3e970: aSIZE_MAXcase for each of the four binary setters, with the unmapped pointer: each returns0x80553101before reading the guest bytes, and the existing checks confirm nothing is stored anderrnostays 71.e1e4aaba03: on Windows those cases first failed (FATAL: C++ exception St12length_error ... cannot be delivered: ... has no unwind data, WinLibs GCC 16.2.0 SEH): GCC placed thestd::__throw_length_errorcall in a cold section the runtime could not unwind. The setters now return0x80553101for a size abovemax_size()before resizing and catch onlystd::bad_alloc, so they throw nostd::length_error. No allocation is attempted for theSIZE_MAXcases, so they are deterministic, also under ASan.At
e1e4aaba03:np_uds|np_trophy|copy_guest_stringtests pass in each of 3 runs. Negative control: with96f1b07783'sRecord.cpp(no size check or catch in the record setters),guest_np_uds_recordsaborts withterminate called after throwing an instance of 'std::length_error'.guest_copy_guest_string,np_uds_events,guest_np_uds_records,guest_np_uds_queries,guest_np_trophy_data,guest_np_trophy_stats,guest_np_trophy_unlocks) pass in each of 3 runs.The original combined change:
Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release,
-DBUILD_TESTING=ON, on91d261cec1(onmaind89f26516c):guest_np_uds_recordsandnp_uds_eventsgain the cases from the originals:0x10) keys, string values, record types and byte buffers, each returning the codes above witherrnoleft at 71 and the object or array unchanged.guest_copy_guest_string,np_uds_events,guest_np_uds_records,guest_np_uds_queries,guest_np_trophy_data,guest_np_trophy_statsandguest_np_trophy_unlockspass, 3 runs.Record.cpp,EventPropertyObject.cppandEventPropertyArray.cppfrommainwith these tests die with SIGSEGV at address0x10. The long-string cases run first and pass there.Windows 11 VM (GeForce GT 1030, WinLibs GCC 16.2.0 POSIX UCRT, Ninja, Release):
91d261cec1.c588fe39baand69869dbe56merged intomain56c87adbdc, Windows 11, i7-12700K, WinLibs GCC 15.2.0): the new tests pass 2/2, three runs.Both:
git merge-treeagainstmain3c07e1d05eis clean.tools/check_conventions.pypasses on the branch and this body.tools/debt_fold.py --checkreports nothing for the fragment.GuestCopyGuestStringandGuestNpUniversalDataSystemRecordspass against the existing runtime, covering the checked guest reads of record keys and values.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T01:31:01Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
91d261cec1:tools/check_conventions.pypassed.guest_copy_guest_string_tests,guest_np_uds_records_tests,np_uds_events_testsbuilt cleanly.guest_copy_guest_string,np_uds_events,guest_np_uds_records):core/libs/prx/libSceNpUniversalDataSystem/src/EventPropertyArray.cpp,core/libs/prx/libSceNpUniversalDataSystem/src/EventPropertyObject.cpp,core/libs/prx/libSceNpUniversalDataSystem/src/NpUniversalDataSystem.hpp,core/libs/prx/libSceNpUniversalDataSystem/src/Record.cpp,core/libs/prx/libc/src/General.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T07:59:03Z.
Review: CHANGES_REQUESTED
Reviewed — comments
Changes are required before merge: address the unchecked allocation failures in the event-property binary setters.
What I ran
Reviewed head
91d261cec1b79ba11fdf2d4007e986df123fe4a6from the prepared diff and pinned reader. No commands or tests were run by me; test results in the description are author-reported.Results
Findings
Blocking
EventPropertyArraySetBinaryandEventPropertyObjectSetBinaryconstructUds::Binarydirectly from the guest-provided size. If allocation fails,std::bad_allocescapes the C API instead of returning the documented error code; the existingCopyTexthelper explicitly translates allocation failure, but these byte-buffer paths do not. Catch allocation failure and return the appropriate error without mutating the object. Changed lines:core/libs/prx/libSceNpUniversalDataSystem/src/EventPropertyArray.cpp:112andcore/libs/prx/libSceNpUniversalDataSystem/src/EventPropertyObject.cpp:136.Non-blocking
None.
Not verified
I read all nine changed repository files listed as included in the manifest:
EventPropertyArray.cpp,EventPropertyObject.cpp,NpUniversalDataSystem.hpp,Record.cpp,Events.cpp,General.cpp,guest_copy_guest_string.cmake,GuestCopyGuestString.cpp, andGuestNpUniversalDataSystemRecords.cpp. I also readdescription.md,commits.md,manifest.json, anddiff.patch.files.jsonwas not available in the reader listing. The full review-folder file contents listing was not provided; excluded files, if any, are not verified. Tests, build, console behavior, and author-reported results were not independently verified.To get this to a good state
Handle allocation failure in both event-property binary setters and verify the behavior with a focused test.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T08:30:51Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: catch allocation failures in both record binary setters and return the record out-of-memory code.
What I ran
Reviewed head
96f1b077836cf946bcba6daf1a43f77cbcecccbdusing the prepared diff and targeted source reads throughrepo_read.py. I ran no commands or tests.Results
Findings
Blocking
core/libs/prx/libSceNpUniversalDataSystem/src/Record.cpp:357andcore/libs/prx/libSceNpUniversalDataSystem/src/Record.cpp:510: both record binary setters constructUds::Binarywith the guest-supplied size without catchingstd::bad_allocorstd::length_error. A sufficiently large size can therefore let an allocation exception escape the C API instead of returningkOutOfMemory; the event-property setters already translate these failures. Catch both exceptions and returnkOutOfMemorybefore attempting the guest copy.Non-blocking
None.
Sources
Not verified
No tests or builds were run. Source review used targeted ranges rather than reading every changed file end-to-end; all 10 changed files were present in the review bundle, and none were excluded there.
To get this to a good state
Catch allocation failures in both record binary setters and return
kOutOfMemory; rerun the relevant UDS tests on the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T09:14:44Z.
Review: COMMENTED
Reviewed — comments
Changes are needed to keep the new checked-copy paths from throwing allocation exceptions through C APIs and to exercise the host out-of-memory behavior.
What I ran
Reviewed head
192b3b8f8fccccb51e52310a1de3e78a29802e6e. I read all ten changed files listed as reviewed in the manifest, including every added line. I did not run tests or build commands; the test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
CopyGuestString_nid_no_patchreturns an error forstd::bad_alloc, butbytes.resize()can also throwstd::length_error; the laterdestination.assign()can throw that exception too.Uds::CopyTextand the record wrappers translate only return code12, so these exceptions can still escape the C APIs in extreme allocation cases (core/libs/prx/libc/src/General.cpp:571,core/libs/prx/libSceNpUniversalDataSystem/src/NpUniversalDataSystem.hpp:38,core/libs/prx/libSceNpUniversalDataSystem/src/Record.cpp:121). Consider translatingstd::length_errorin the helper into the existing out-of-memory result, consistently with the binary setters.Not verified
I did not run the author-reported Linux or Windows test suites, the convention/debt checks, or a merge-preview check. The author reports those passed on earlier revisions; they are not results from this review. I read the changed files listed in the review manifest; no changed file was excluded.
To get this to a good state
Nothing is required. Optional: translate
std::length_errorin the string-copy path and add allocation-failure coverage for the out-of-memory behavior.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T09:49:34Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the available evidence supports merging, though I did not run checks on this head.
What I ran
Read the prepared diff, manifest, description, commit list, and all changed-file lines listed in the manifest at head
10f4a3e9708901246578409d9607b51ff7b9bda7. Read relatedGeneral.hppand theGuestCopyInimplementation inGeneral.cpp. No test or build commands were run; the test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Builds, tests, Windows and console behavior were not independently verified on this head. Author-reported testing covers earlier commits; the description reports Linux tests on commits through
192b3b8f8fand Windows tests on91d261cec1.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T10:21:59Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
e1e4aaba038055a43ba5c85bf9021f9e52202594. I inspected the prepared description, commit list, manifest, diff, all nine included changed-file texts, and the changedCopyGuestString_nid_no_patchimplementation. No tests or build commands were run; the test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
Not verified
I did not run the reported Linux or Windows test suites, negative controls, convention checks, debt check, or merge-tree check. All nine changed files were included in the review folder and read:
EventPropertyArray.cpp,EventPropertyObject.cpp,NpUniversalDataSystem.hpp,Record.cpp,Events.cpp,General.cpp,guest_copy_guest_string.cmake,GuestCopyGuestString.cpp, andGuestNpUniversalDataSystemRecords.cpp. No files were excluded by rule.To get this to a good state
Nothing is required. The allocation-failure coverage point is optional.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T14:57:24Z.
Review: COMMENTED
Built the changed sources and ran
GuestCopyGuestString,GuestNpUniversalDataSystemRecords, andEventsagainst the existing Linux runtime. All three fixtures passed, covering checked guest reads for record keys and values and the event handling paths.Eventsreported that its comma-decimal locale case was unavailable on this host.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T20:03:54Z.
Review: COMMENTED
Actionable comments
8429f513-44f8-4a47-845c-9698228c369bReviewing files that changed from the base of the PR and between
f6caba6040and01116cf278.core/libs/prx/libSceNpUniversalDataSystem/src/EventPropertyArray.cppcore/libs/prx/libSceNpUniversalDataSystem/src/EventPropertyObject.cppcore/libs/prx/libSceNpUniversalDataSystem/src/NpUniversalDataSystem.hppcore/libs/prx/libSceNpUniversalDataSystem/src/Record.cppcore/libs/prx/libSceNpUniversalDataSystem/tests/Events.cppcore/libs/prx/libc/src/General.cppcore/libs/prx/libc/tests/cmake/guest_copy_guest_string.cmakecore/libs/tests/GuestCopyGuestString.cppcore/libs/tests/GuestNpUniversalDataSystemRecords.cppdocs/dev/debt/changes/fix-npuds-guest-copies-combined.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T20:20:43Z.
Review: APPROVED
Reviewed — looks good
The inspected changes safely copy guest strings and binary values before storing them, with focused coverage for unreadable pointers and oversized binary inputs.
What I ran
Reviewed head
01116cf278d68d02fe243001b46713ddd4f0a1cdusing the pinnedrepo_read.pyreader and the prepared review materials. I ran no tests, builds, or other executable checks. The review workspace provided the environment; no compiler or host details were used.All 10 files listed as reviewed in
files.jsonwere read. No files were excluded by rule.Results
Negative control
The negative controls described by the author were not run during this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The test runs, negative controls, and console behavior described in the PR body were not independently verified. No build or runtime checks were performed.
To get this to a good state
Nothing is required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.