fix(libSceJson2): safely probe the text of the Value text constructor and set #20682
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20682"
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-15T12:21:46Z.
What
sce::Json::Value(const char*)andValue::set(const char*)wrapped the guest text in astd::string_view, which ranstrlenover it in place, so non-null text pointing at unmapped memory faulted the host.Both now measure the text first with a small
GuestTextLengthhelper. It copies one page-aligned chunk at a time into a 4 KiB stack buffer withGuestCopyIn_nid_no_patchand stops at the terminator. Then they build the string from the guest text with that length. The text is not copied to the host heap:guest_json_float_failurerequires recovery values to use only the guest allocator, so the existing guest-allocatedScopedStringstill does the copy. Strings of any length still work, since the helper walks page by page rather than to a fixed cap.Unreadable text is handled the way each call already handles null text: the constructor makes an empty string, and
setthrowsstd::invalid_argument("unreadable text"). The values, the allocator-failure behaviour thatguest_json_copy_failurepins, and every result for readable text are unchanged.There were no tests for these two calls on plain text, so this adds
GuestJsonValueText.cpp. The debt entry goes in a fragment underdocs/dev/debt/changes/and records this as unmeasured.Tested
Linux (Ubuntu 26.04.1), GCC 15.2, Release.
guest_json_value_text:Value("text")serializes as"text";0x10) both serialize as"";set("updated")replaces it, andset(0x10)throwsstd::invalid_argumentand keeps"updated".guest_json*tests pass, includingguest_json_copy_failure(allocation-budget sweep) andguest_json_float_failure(guest-allocator-only recovery values).main'sExport.cppand this test,guest_json_value_textsegfaults.git merge-treeagainst #16207 (the other open PR onlibSceJson2/Export.cpp): no conflicts.tools/check_conventions.pypasses on the branch and this body;tools/debt_fold.py --checkpasses with the fragment applied tomain.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 MarcZX10 on 2026-11-15T13:00:03Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected implementation and tests support merging.
What I ran
Reviewed head
dd545ae147a8f541d7d3dcadd3ffd1fba10c6b60. I read all four changed files listed inreview/manifest.json, along with the prepared description, commits, and diff. I did not run commands or tests.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported Linux test runs and negative control were not independently verified.
review/files.jsonwas unavailable through the reader; the changed-file list and inclusion status were confirmed with the review directory listing. No files were excluded per the manifest.To get this to a good state
Nothing is required.