Repository navigation
fix(libSceIcu): read hashed strings through guest copies - #24383
oneandonlydean merged 1 commit into
Conversation
ustr_hashUCharsN, ustr_hashCharsN and ustr_hashICharsN passed guest pointers straight to ICU, so an unreadable string crashed the host. ICU only samples every ((length - 32) / 32 + 1)-th unit, at most 63 of them, so the wrappers now copy just those units through GuestCopyIn_nid_no_patch and hash them with ICU, which samples every unit of an array that short: the value is unchanged and no unit ICU skips is read. An unreadable sampled unit throws std::invalid_argument; errno is preserved. Null strings and nonpositive lengths still go to ICU, which reads nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 8450b87ac9:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_icu_string_hash_testsbuilt cleanly. - CTest (
guest_icu_string_hash):1/1 Test #4050: guest_icu_string_hash ............ Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceIcu/StringHash.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4050: guest_icu_string_hash ............***Exception: SegFault 0.41 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified HashSamples in core/libs/prx/libSceIcu/StringHash.cpp against ICU STRING_HASH algorithm: for length <= 0 or nullptr, correctly delegates to ICU functions which return 0.
- Checked bounds and sample count: length > 0 with step = (length - 32) / 32 + 1 produces at most 63 samples, preventing buffer overflow on samples[MaximumSamples].
- Verified GuestCopyIn_nid_no_patch memory safety, error handling with std::invalid_argument, and preservation of errno across copy checks.
- Verified LP64 vs LLP64 portability and 64-bit step/offset arithmetic in core/libs/prx/libSceIcu/StringHash.cpp and tests/StringHash.cpp.
- Checked AGENTS.md compliance: no comments in source code, technical debt fragment properly added to docs/dev/debt/changes/, and CMakeLists.txt properly wired with test target and Windows unwind configuration.
Looks Good To Me
|
Tested
AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the code read supports the reported sampled-copy behavior, and the author reports Linux harness coverage while Windows and the full build remain unverified.
What I ran
Reviewed head 8450b87ac9da4bec8da3f3cacc70311965b04f75. I read description.md, commits.md, manifest.json, diff.patch, and all four changed files listed as reviewed. I did not run build or tests; the Linux harness and convention checks are author-reported.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed files | passed | All four reviewed files read |
| Build and tests | not run | Linux harness results are author-reported |
| Windows behavior | not run | VirtualProtect test branch unverified |
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests or build were run during this review. Windows behavior and the full project build were not verified. No changed files were excluded; files.json was not available in the review bundle.
To get this to a good state
Nothing is required.
What
ustr_hashUCharsN,ustr_hashCharsNandustr_hashICharsNpassed guest pointers straight to bundled ICU 78.1, so an unreadable string crashed the host instead of throwing.ICU's
STRING_HASH(ustring.cpp, unchanged from 68.2) does not read the whole string: it samples everyinc = (length - 32) / 32 + 1-th unit, which is at most 63 units for any length (withlength = 32 + 32q + r,0 <= r < 32, that is32 + ceil(r / (q + 1))). Copying the whole range would read pages ICU never touches, so the wrappers copy only the sampled units throughGuestCopyIn_nid_no_patchand hash that array with the ICU function. For fewer than 64 units ICU's step is 1, so it hashes every copied unit in order and the value is unchanged.An unreadable sampled unit throws
std::invalid_argument, anderrnois preserved, as inuprv_strdup(586b989). Null strings and nonpositive lengths still go to ICU, which reads nothing and returns 0.The existing
ustr_hash*checks intests/Availability.cppare kept; the newguest_icu_string_hashtest covers these exports on their own.Tested
Linux only (Ubuntu 24.04 container, GCC 13.3,
-Wall -Wextraclean): a minimal harness that builds the bundled ICUcommonsources with the project's definitions,StringHash.cppandtests/StringHash.cpp, withGuestCopyIn_nid_no_patchbacked byprocess_vm_readvon the own process. No full build and no Windows run, so theVirtualProtectbranch of the test is untested.StringHash.cppfrommainit crashes with SIGSEGV.STRING_HASHat lengths around every step change (31 to 97, 4095 to 4097, 131103/131104, up to 300000); null strings hash to 0 and nonpositive lengths read nothing; unreadable pointers throw and keeperrno; a 300000-unit string whose unsampled tail lies in aPROT_NONEpage hashes as in ICU, and shifting it by one unit so the last sample lands in that page throws.python tools/check_conventions.py --base upstream/mainandpython tools/debt_fold.py --checkpass.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