feat(libSceIcu): implement the uhash UnicodeString hash and compare helpers #24291
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24291"
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 Callimann8 on 2026-11-20T13:09:37Z.
What
Implements the four
UnicodeStringhash-table callbacks in libSceIcu that were throwing stubs inLegacyExports.cpp:uhash_hashUnicodeString,uhash_hashCaselessUnicodeString,uhash_compareUnicodeStringanduhash_compareCaselessUnicodeString.icu::Hashtable(inline in ICU'shash.h) installs these as its key callbacks, so guest code built against it passes their addresses straight intouhash.They live in a new
UnicodeStringHash.cppand follow ICU 68.2's uhash_us.cpp and unistr_case.cpp:UElement(Icu::ElementinLegacyExports.hpp, a union of a pointer and anint32_t) passed by value.icu::UnicodeStringis read with checked copies using the public ICU 68 64-bit layout from unistr.h:fLengthAndFlagsat offset 8, the 27-unit stack buffer at 10, the long length at 12 and the heap array at 24. A bogus string becomes a bogus host string. Otherwise the text is copied into a hosticu::UnicodeString.hashCode(), orfoldCase().hashCode()for the caseless one. The compares return true for the same pointer, false when only one key is null, and otherwiseoperator==, orcaseCompare(..., U_FOLD_CASE_DEFAULT) == 0, all from the bundled ICU.NotImplemented_nid_no_patch. The new debt fragment records that the console prototypes are unverified.Tested
Linux (Ubuntu 24.04, GCC 13.3). New
guest_icu_unicode_string_hashtest: signature checks. It checks parity with the bundled ICU for both hashes on hand-built guest objects (stack buffer, short heap length, large-length form), on real hosticu::UnicodeStringobjects (this also checks the layout constants), on bogus strings and null keys. It checks both compares across every pair of 12 strings (empty, ASCII, mixed case, ß/STRASSE, Greek, 27 units, heap, 1100 units, bogus) and their copies, plus same-pointer, null and mixed bogus cases. Unreadable objects, a dangling array and a negative length throw witherrnopreserved. Passes in Release and in an ASan + UBSan build (ANYPS5_ENABLE_ASAN=ON,-fsanitize=undefined).guest_icu_converter_aliasesandguest_icu_converter_available_namesstill pass. Only libSceIcu changed, so the full emulator build was skipped. Not tested on a console.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-20T13:16:53Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and focused tests provide evidence for merging, with console ABI and behavior still unverified.
What I ran
Reviewed head
8b9877b082a0efc9aef013bd04314207c7462816. I read the review description, commit summary, diff, manifest, and full text of all five changed files. No test commands were run; the test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
Not verified
Console behavior and ABI, and the reported Linux, Release, ASan, and UBSan test runs, were not independently verified. No changed files were excluded; all five files listed as reviewed in the manifest were read.
files.jsonwas not available through the reader.To get this to a good state
Nothing is required. Optional: compare the callbacks against console behavior and ABI when available.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T13:31:13Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
8b9877b082:tools/check_conventions.pypassed.guest_icu_unicode_string_hash_testsbuilt cleanly.guest_icu_unicode_string_hash):core/libs/prx/libSceIcu/LegacyExports.cpp,core/libs/prx/libSceIcu/include/LegacyExports.hpp,core/libs/prx/libSceIcu/UnicodeStringHash.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T23:58:16Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: reject or safely bound guest-controlled long lengths before allocating the copy buffer.
What I ran
Reviewed head
53c3825b46f0665247a5c3e9e8ecc22487e0caddusingrepo_read.pyto read the prepared diff and targeted source context. No build or tests were run.Results
Findings
Blocking
core/libs/prx/libSceIcu/UnicodeStringHash.cpp:44allocates a vector using the guest-provided long-form length before checking whether the guest array is readable. A malformed string can provide a very large positive length and trigger a multi-gigabyte allocation attempt, risking host memory exhaustion or an uncaught allocation exception. Validate the guest range or impose a safe bound before allocating.Non-blocking
None.
Not verified
The PR description reports Linux Release and ASan/UBSan test runs; these were not run during this review. Console ABI and behavior are explicitly unverified. The full contents of
core/libs/prx/libSceIcu/LegacyExports.cppwere not read; its diff only removes the four previous stubs. Files read:core/libs/prx/libSceIcu/CMakeLists.txt,core/libs/prx/libSceIcu/UnicodeStringHash.cpp,core/libs/prx/libSceIcu/include/LegacyExports.hpp(targeted ranges), andreview/description.md,review/commits.md,review/manifest.json,review/diff.patch. All changed files are included in the review folder; the completeLegacyExports.cppwas not read.To get this to a good state
Bound or validate long-form lengths before allocating, then rerun the new malformed-input test and relevant sanitizer checks on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T00:31:50Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and tests support merging, with console ABI behavior still unverified.
What I ran
Reviewed head
238a706afe9a12e1d453ad9c306a603496c05a45from the prepared diff and targeted source reads. I did not run tests or a build; reported test results below come from the PR description.Files read:
description.md,commits.md,manifest.json,diff.patch,core/libs/prx/libSceIcu/UnicodeStringHash.cpp,core/libs/prx/libSceIcu/include/LegacyExports.hpp,core/libs/prx/libSceIcu/CMakeLists.txt,core/libs/prx/libSceIcu/tests/UnicodeStringHash.cpp, andcore/libs/prx/libc/src/General.cpp. The manifest lists six changed files; I read relevant diff content for all six. No changed files were excluded in the manifest.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The callback ABI and
UnicodeStringlayout against console behavior remain unverified, as recorded in the PR. I did not independently run the reported Linux tests.files.jsonwas not available through the reader, so the excluded-file list could not be checked directly; the manifest lists six changed files and marks each included.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T17:58:30Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
4c49ec6b88cb4af595a04bd60fd8448db2d80ce3against the prepared diff and targeted source context. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
UnicodeStringHash.cpp:54increments a signed 32-bit offset by 256. If a valid guest string has a length nearINT32_MAX, the increment can overflow after the final chunk, causing undefined behavior. Use a wider offset type or advance by the current chunk count.Not verified
No build, tests, console behavior, or ABI comparison was performed. The reported Linux runs are author-reported. Read all changed files listed in the manifest:
CMakeLists.txt,LegacyExports.cpp(no added lines),UnicodeStringHash.cpp,include/LegacyExports.hpp,tests/UnicodeStringHash.cpp, anddocs/dev/debt/changes/feat-icu-uhash-unicode-string.md. No changed files were excluded.To get this to a good state
Nothing is required. Consider avoiding signed overflow in the long-string chunk loop.
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.