Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
magnub:test/icu-unicode-string-hash-heap-lifetime
Dec 3, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
magnub:test/icu-unicode-string-hash-heap-lifetime

Conversation

@magnub

@magnub magnub commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 433136c2-3a07-402b-b42c-6ddbed15a4d0
Commits

Reviewing files that changed from the base of the PR and between 8a231ff and 3c81fcd.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Changes: Unicode hash test

Layer / File(s) Summary
Heap string test input
core/libs/prx/libSceIcu/tests/UnicodeStringHash.cpp
The test stores "HELLO" in upperText and passes the variable to Heap. The comparison assertions are unchanged.

Suggested reviewers: callimann8

Change: Other

Merge Risk: Minimal · previous review 8a231

This test-only change fixes a lifetime bug in the Unicode string hash test and does not affect production behavior. No merge-blocking risk remains.

Security architecture risk: Minimal · up to 8a231

The fix corrects the lifetime of test data without changing how the shipped software handles strings.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 234f5e34-b597-48d8-b27e-45788fb565b3
Commits

Reviewing files that changed from the base of the PR and between 2b6c1b0 and 8a231ff.

Files selected for processing: 1

  • core/libs/prx/libSceIcu/tests/UnicodeStringHash.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@JJenkx

JJenkx commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Windows at this head (8a231ffdc316): guest_icu_unicode_string_hash passes, 3/3 runs. This is the CTest of the executable that compiles the changed UnicodeStringHash.cpp.

Setup:

  • Windows 11 22621, Ryzen 9 5950X, MinGW-w64 GCC 15.2 UCRT r7, Release.
  • The exact PR head was built (not merged into main).
  • 3 runs through the shared FIFO.

The added test lines have no platform guard.

AI-assisted: yes.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 14340 core/libs/prx/libSceIcu/tests/UnicodeStringHash.cpp
PR 14443 core/libs/prx/libSceIcu/tests/UnicodeStringHash.cpp

@Plyxen Plyxen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 NobleBrains left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@oneandonlydean
oneandonlydean merged commit c1593e4 into boykopovar:main Dec 3, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants