test(libSceIcu): keep the string behind a heap UnicodeString alive #27828

Merged
magnub merged 1 commit from upstream-pr/27828 into main 2026-12-03 14:31:12 +00:00
magnub commented 2026-11-27 14:30:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by magnub on 2026-11-27T14:30:04Z.


What

In TestHashAndCompare (from #24291), Heap(u"HELLO", false) builds the guest UnicodeString from a temporary std::u16string, and Heap stores text.data() as the array pointer. The temporary is destroyed at the end of that statement, so upper points into dead stack memory when the following checks read it. With libstdc++ the characters usually survive there, so the test passes on Linux. With libc++ they do not, and uhash_compareCaselessUnicodeString(Key(&hello), Key(&upper)) == 1 fails on macOS ("ICU UnicodeString hash check failed at line 139").

The string now lives in upperText for the rest of the function. The other temporary Heap calls overwrite the array pointer or fail on the length before the array is read, so they are unchanged. Test-only change.

Tested

macOS 27.0.1 (26A434) on an Apple M1 Pro, Apple clang 21.0.0, x86_64 Release build under Rosetta 2. Build: main 2b6c1b0445 plus #17425, #11049, #26739 and #25331, which the macOS build needs:

  • main: guest_icu_unicode_string_hash fails 0/3 at line 139.
  • this PR: it passes 3/3.

The same pattern (a const std::u16string& parameter bound to a literal, its data() kept past the statement) reports stack-use-after-scope under AddressSanitizer with GCC 13 on Ubuntu 24.04. tools/check_conventions.py --base origin/main passes. Log attached.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

https://claude.ai/code/session_012LL9hfx4BY6MbUCYMduDAQ

Summary by CodeRabbit

  • Tests
    • Updated an internal test to use a UTF-16 string value when checking heap-string behavior. Existing comparison checks are unchanged.
    • No changes to user-facing functionality.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5528308648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27828). Originally posted by [magnub](https://github.com/magnub) on 2026-11-27T14:30:04Z. --- ### What In `TestHashAndCompare` (from #24291), `Heap(u"HELLO", false)` builds the guest `UnicodeString` from a temporary `std::u16string`, and `Heap` stores `text.data()` as the array pointer. The temporary is destroyed at the end of that statement, so `upper` points into dead stack memory when the following checks read it. With libstdc++ the characters usually survive there, so the test passes on Linux. With libc++ they do not, and `uhash_compareCaselessUnicodeString(Key(&hello), Key(&upper)) == 1` fails on macOS ("ICU UnicodeString hash check failed at line 139"). The string now lives in `upperText` for the rest of the function. The other temporary `Heap` calls overwrite the array pointer or fail on the length before the array is read, so they are unchanged. Test-only change. ### Tested macOS 27.0.1 (26A434) on an Apple M1 Pro, Apple clang 21.0.0, x86_64 Release build under Rosetta 2. Build: `main` `2b6c1b0445` plus #17425, #11049, #26739 and #25331, which the macOS build needs: - main: `guest_icu_unicode_string_hash` fails 0/3 at line 139. - this PR: it passes 3/3. The same pattern (a `const std::u16string&` parameter bound to a literal, its `data()` kept past the statement) reports `stack-use-after-scope` under AddressSanitizer with GCC 13 on Ubuntu 24.04. `tools/check_conventions.py --base origin/main` passes. Log attached. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_012LL9hfx4BY6MbUCYMduDAQ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Tests** * Updated an internal test to use a UTF-16 string value when checking heap-string behavior. Existing comparison checks are unchanged. * No changes to user-facing functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-27 14:40:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T14:40:55Z.

Review: APPROVED


Reviewed — looks good

The fix keeps the UTF-16 backing string alive for the heap guest object used by the comparison checks; no blocking defect was found in the changed code.

What I ran

Reviewed head 8a231ffdc316672f8a0b25deb4e03a4ede756d44. Read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, and the full changed file core/libs/prx/libSceIcu/tests/UnicodeStringHash.cpp through repo_read.py. No build or tests were run.

Results

Check Result Note
Changed code review passed Backing string lifetime is extended
Build and tests not run No execution performed

Findings

Blocking

None.

Non-blocking

None.

Not verified

review/files.json was not available through the reader, so excluded-file metadata was not confirmed. The manifest lists one changed file, and its full text was read. Build and test behavior, including the author-reported platform results, was not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6089783714 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27828#pullrequestreview-6089783714). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T14:40:55Z. **Review:** APPROVED --- # Reviewed — looks good The fix keeps the UTF-16 backing string alive for the heap guest object used by the comparison checks; no blocking defect was found in the changed code. ## What I ran Reviewed head `8a231ffdc316672f8a0b25deb4e03a4ede756d44`. Read `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`, and the full changed file `core/libs/prx/libSceIcu/tests/UnicodeStringHash.cpp` through `repo_read.py`. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Backing string lifetime is extended | | Build and tests | not run | No execution performed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified `review/files.json` was not available through the reader, so excluded-file metadata was not confirmed. The manifest lists one changed file, and its full text was read. Build and test behavior, including the author-reported platform results, was not independently verified. ## To get this to a good state Nothing is required.
PrivacyOnion commented 2026-11-27 14:48:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T14:48:31Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 8a231ffdc3:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_icu_unicode_string_hash_tests built cleanly.
  • CTest (guest_icu_unicode_string_hash):
    1/1 Test #4469: guest_icu_unicode_string_hash ....   Passed    0.18 sec
    100% tests passed, 0 tests failed out of 1
    
  • Code reading:
    • Verified core/libs/prx/libSceIcu/tests/UnicodeStringHash.cpp:137-138 lifetime fix where upperText (std::u16string) guarantees the backing char16_t buffer stays alive throughout the subsequent comparisons
    • Confirmed heap UnicodeString pointer dereferencing in uhash_compareUnicodeString_nid_postfix and uhash_compareCaselessUnicodeString_nid_postfix does not result in stack-use-after-scope
    • Verified AGENTS.md conventions compliance (no code comments added, conventional commit, template intact, mechanical checks passed)
    • Confirmed cross-platform validity across Linux, macOS, and Windows without platform guards or ABI mismatches

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6089880444 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27828#pullrequestreview-6089880444). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-27T14:48:31Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `8a231ffdc3`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_icu_unicode_string_hash_tests` built cleanly. - **CTest** (`guest_icu_unicode_string_hash`): ``` 1/1 Test #4469: guest_icu_unicode_string_hash .... Passed 0.18 sec 100% tests passed, 0 tests failed out of 1 ``` - **Code reading**: - Verified core/libs/prx/libSceIcu/tests/UnicodeStringHash.cpp:137-138 lifetime fix where upperText (std::u16string) guarantees the backing char16_t buffer stays alive throughout the subsequent comparisons - Confirmed heap UnicodeString pointer dereferencing in uhash_compareUnicodeString_nid_postfix and uhash_compareCaselessUnicodeString_nid_postfix does not result in stack-use-after-scope - Verified AGENTS.md conventions compliance (no code comments added, conventional commit, template intact, mechanical checks passed) - Confirmed cross-platform validity across Linux, macOS, and Windows without platform guards or ABI mismatches Looks Good To Me
Plyxen commented 2026-11-28 05:06:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T05:06:18Z.

Review: APPROVED


Checked head 8a231ffdc3. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to main a163d4b886 together with #27930, #27929, #27926, #27925, #27924, #27923, #27922, #27901, #27771, #27755, #27748, #27682, #27765. tools/check_conventions.py --head and tools/debt_fold.py --check passed and the full build succeeded. guest_icu_unicode_string_hash passes. In the full CPU suite (5,120 tests) the only failures are unrelated:

  • windows_read_trap_unknown fails on main too (fixed in #28028).
  • frame_capture_minimize, jpeg_external_toolchain and guest_pthread_mutex_contention are timeouts under load; they pass when run on their own.
  • guest_audio_in_capture passes 20/20 on main and with #27922.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6095939160 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27828#pullrequestreview-6095939160). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-28T05:06:18Z. **Review:** APPROVED --- Checked head `8a231ffdc3`. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to `main` `a163d4b886` together with #27930, #27929, #27926, #27925, #27924, #27923, #27922, #27901, #27771, #27755, #27748, #27682, #27765. `tools/check_conventions.py --head` and `tools/debt_fold.py --check` passed and the full build succeeded. `guest_icu_unicode_string_hash` passes. In the full CPU suite (5,120 tests) the only failures are unrelated: - `windows_read_trap_unknown` fails on `main` too (fixed in #28028). - `frame_capture_minimize`, `jpeg_external_toolchain` and `guest_pthread_mutex_contention` are timeouts under load; they pass when run on their own. - `guest_audio_in_capture` passes 20/20 on `main` and with #27922. AI-assisted: yes (Claude Code)
NobleBrains commented 2026-12-01 00:22:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NobleBrains on 2026-12-01T00:22:06Z.

Review: APPROVED


Confirmed on macOS 15.

Setup: Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, BUILD_TESTING=ON. These are the OS and compiler generation of the macos-15 runner.
Tree: main 93d64f2d1e + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (main does not build on macOS without them, see #28168), + #22091, #28369, #28075, #28076, #28284, then #17878, #20161, #25134, #26806, #22932, #28373, #27828, #27950, #27582, #24311 merged one after another. All merged cleanly.

guest_icu_unicode_string_hash failures
same tree before this PR 3/3
with this PR at 3c81fcd938 0/5

Full ctest -j 6 after all of them: 7047/7066 pass. Compared with the run before the second group of merges, no test fails that passed before.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6122950120 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27828#pullrequestreview-6122950120). Originally posted by [NobleBrains](https://github.com/NobleBrains) on 2026-12-01T00:22:06Z. **Review:** APPROVED --- Confirmed on macOS 15. **Setup:** Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, `BUILD_TESTING=ON`. These are the OS and compiler generation of the `macos-15` runner. **Tree:** `main` `93d64f2d1e` + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (`main` does not build on macOS without them, see #28168), + #22091, #28369, #28075, #28076, #28284, then #17878, #20161, #25134, #26806, #22932, #28373, #27828, #27950, #27582, #24311 merged one after another. All merged cleanly. | `guest_icu_unicode_string_hash` | failures | |---|---| | same tree before this PR | 3/3 | | with this PR at `3c81fcd938` | 0/5 | **Full `ctest -j 6`** after all of them: 7047/7066 pass. Compared with the run before the second group of merges, no test fails that passed before. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 09:13:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T09:13:12Z.

Review: COMMENTED


The Linux UnicodeStringHash fixture passed with the pinned ICU runtime. I checked the ownership change in the fixture. The named UTF-16 string now remains alive through the hash and comparison checks that use its backing array.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6166731439 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27828#pullrequestreview-6166731439). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T09:13:12Z. **Review:** COMMENTED --- The Linux `UnicodeStringHash` fixture passed with the pinned ICU runtime. I checked the ownership change in the fixture. The named UTF-16 string now remains alive through the hash and comparison checks that use its backing array. AI-assisted: yes.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!27828
No description provided.