You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(libSceIcu): keep the string behind a heap UnicodeString alive - #27828
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: main2b6c1b0445 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
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
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.
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.
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
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.
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 maina163d4b886 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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
In
TestHashAndCompare(from #24291),Heap(u"HELLO", false)builds the guestUnicodeStringfrom a temporarystd::u16string, andHeapstorestext.data()as the array pointer. The temporary is destroyed at the end of that statement, soupperpoints 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, anduhash_compareCaselessUnicodeString(Key(&hello), Key(&upper)) == 1fails on macOS ("ICU UnicodeString hash check failed at line 139").The string now lives in
upperTextfor the rest of the function. The other temporaryHeapcalls 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:
main2b6c1b0445plus #17425, #11049, #26739 and #25331, which the macOS build needs:guest_icu_unicode_string_hashfails 0/3 at line 139.The same pattern (a
const std::u16string¶meter bound to a literal, itsdata()kept past the statement) reportsstack-use-after-scopeunder AddressSanitizer with GCC 13 on Ubuntu 24.04.tools/check_conventions.py --base origin/mainpasses. Log attached.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
https://claude.ai/code/session_012LL9hfx4BY6MbUCYMduDAQ
Summary by CodeRabbit