Skip to content

fix(libSceIcu): throw for a null locale in the locale component getters instead of failing - #20074

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
roboterspinne:fix/libsceicu-null-locale-getters
Nov 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
roboterspinne:fix/libsceicu-null-locale-getters

Conversation

@roboterspinne

Copy link
Copy Markdown
Contributor

What

uloc_getLanguage, uloc_getCountry and uloc_getScript (through Component, core/libs/prx/libSceIcu/LocaleCore.cpp:146-156 on main b4c5a38, null check at :149-152), uloc_getBaseName (:180-183) and uloc_canonicalize (:223-226) set U_ILLEGAL_ARGUMENT_ERROR (1) and return 0 when the locale is null. ICU does not treat a null locale as an error in these functions: it means the default locale.

Tested

Windows 11, WinLibs GCC 15.2.0, Ninja, Release, BUILD_TESTING=ON, build directory configured through its 8.3 short path. Before every run, each core/libs/libs/unpatched/*.prx that also exists in <build>/tests was copied there with cmake -E copy_if_different. The md5sum of libSceIcu.prx matched in both places each time.

  • Counter-check on unchanged code (LocaleCore.cpp of b4c5a38, new test in place). Built with cmake --build <build> --parallel 4 --target guest_icu_locale_core_tests (exit 0). ctest --test-dir <build> -R '^guest_icu_locale_core$' --output-on-failure failed with Exit code 0xc0000409 after Assertion failed: thrown && status == 0 && output[0] == 'Q', file core/libs/tests/GuestIcuLocaleCore.cpp, line 119.
  • With the change: same build command (exit 0), then ctest --test-dir <build> -R '^guest_icu_locale_core$' --output-on-failure passed.
  • Related tests: ctest --test-dir <build> -R '^guest_icu_' --show-only=json-v1 lists the 43 tests registered in core/libs/prx/libSceIcu/CMakeLists.txt. All 43 executables were built in one cmake --build <build> --parallel 4 --target guest_icu_bidi_tests guest_icu_case_mapping_tests guest_icu_character_digits_tests guest_icu_character_tests guest_icu_charset_detection_tests guest_icu_code_points_tests guest_icu_compare_iter_tests guest_icu_compare_tests guest_icu_comparison_tests guest_icu_configuration_tests guest_icu_constrained_field_position_tests guest_icu_converter_callbacks_tests guest_icu_converter_helpers_tests guest_icu_copy_guest_memory_tests guest_icu_copy_tests guest_icu_cstring_tests guest_icu_enumeration_tests guest_icu_error_name_tests guest_icu_iterator_tests guest_icu_java_utf8_tests guest_icu_language_tag_tests guest_icu_locale_core_tests guest_icu_locale_map_tests guest_icu_locale_tests guest_icu_normalization_tests guest_icu_numeric_tests guest_icu_properties_tests guest_icu_recovered_signatures_tests guest_icu_resource_tests guest_icu_right_to_left_tests guest_icu_script_tests guest_icu_search_tests guest_icu_set_tests guest_icu_space_tests guest_icu_terminate_buffer_tests guest_icu_tokenize_tests guest_icu_unescape_tests guest_icu_unicode_data_tests guest_icu_utf16_search_tests guest_icu_utf32_tests guest_icu_utf8_tests guest_icu_version_extents_tests guest_icu_version_tests (exit 0), and every test resolves to an executable. ctest --test-dir <build> -R '^guest_icu_' --output-on-failure: 43/43 passed.
  • Negative control at the end. Only LocaleCore.cpp was reverted to b4c5a38, with the test kept, and guest_icu_locale_core_tests was rebuilt (exit 0). -R '^guest_icu_locale_core$' failed again with the same assertion at line 119 and 0xc0000409. With the change restored and the target rebuilt (exit 0), it passed, and -R '^guest_icu_' passed 43/43.
  • After the i-default sentence was added to the debt entry (no code or test change), the 43 targets were rebuilt (exit 0), the .prx files were synced again with matching md5sum, and -R '^guest_icu_locale_core$' and -R '^guest_icu_' passed (1/1 and 43/43).
  • After a rebase onto main 0f4538f (no file this pull request changes differs there from b4c5a38), 58362dc was rebuilt and checked the same way, with the .prx copies synced and their md5sum matching before every run: -R '^guest_icu_' passes 43 of 43; with LocaleCore.cpp of 0f4538f guest_icu_locale_core fails with Exit code 0xc0000409 after the assertion at GuestIcuLocaleCore.cpp:119; with the change restored and rebuilt, 43 of 43 pass.
  • Not run here: Linux and macOS. The Linux bullet above explains why the negative control fails there too.
  • python tools/check_conventions.py --base upstream/main --head HEAD with this title and description passed.

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
  • 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)

…rs instead of failing

ICU treats a null locale ID in uloc_getLanguage, uloc_getCountry,
uloc_getScript, uloc_getBaseName and uloc_canonicalize as the default
locale (uloc.cpp calls uloc_getDefault), but these exports set
U_ILLEGAL_ARGUMENT_ERROR and returned 0. uloc_getDefault is not
implemented here, so they now call NotImplemented_nid_no_patch instead
of reporting a made-up error. A failing incoming status still returns 0
first, and uloc_getKeywordValue keeps its error, which matches ICU.
@github-actions

Copy link
Copy Markdown

Progress report (3ffcba6 → 58362dc)

📉 System libraries: 40.41% (-0.01%, -5 reverted functions)

⚠️ 5 went back to stubs
Library Name
libSceIcu uloc_canonicalize
libSceIcu uloc_getBaseName
libSceIcu uloc_getCountry
libSceIcu uloc_getLanguage
libSceIcu uloc_getScript

Changed libraries (implemented exports)

Library Before After Change
libSceIcu 211/2757 (7.65%) 206/2757 (7.47%) -0.18%

@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 58362dc52b:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_icu_locale_core_tests built cleanly.
  • CTest (guest_icu_locale_core):
    1/1 Test #3398: guest_icu_locale_core ............   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIcu/LocaleCore.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3398: guest_icu_locale_core ............Subprocess aborted***Exception:   0.31 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • LocaleCore.cpp: Component, uloc_getBaseName, uloc_canonicalize - Verified that incoming error status checks (!status || *status > 0) precede null locale checks, correctly returning 0 and preserving error status without throwing.
    • LocaleCore.cpp: uloc_getLanguage, uloc_getCountry, uloc_getScript, uloc_getBaseName, uloc_canonicalize - Verified that null locale arguments invoke NotImplemented_nid_no_patch with explicit diagnostic messages rather than returning fake kIllegalArgument (1) errors, preventing undefined behavior in Parse() from constructing std::string_view(nullptr).
    • LocaleCore.cpp: uloc_getKeywordValue - Verified that keyword lookup correctly keeps its null locale check returning kIllegalArgument (1), strictly matching upstream ICU ulocimp_getKeywordValue behavior.
    • core/libs/tests/GuestIcuLocaleCore.cpp: Verified that the test matrix exercises all five getters with null locale inputs, checking both std::runtime_error throwing on status 0 and early return preservation on status 15 (kBufferOverflow) while ensuring output buffers remain untouched.
    • docs/dev/debt/libSceIcu.md: Verified the technical debt entry accurately documents the unimplemented default locale resolution via uloc_getDefault and the unhandled i-default alias, formatting links and closing criteria per conventions.
    • LocaleCore.cpp & GuestIcuLocaleCore.cpp: Verified strict AGENTS.md compliance, including zero comments in code, correct header inclusions (prx/libc/include/General.hpp, ), and cross-platform LP64/LLP64 type safety.

Looks Good To Me

@oneandonlydean
oneandonlydean merged commit 3f56b8a into boykopovar:main Nov 14, 2026
14 checks passed
@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 10965 docs/dev/debt/libSceIcu.md
PR 14123 docs/dev/debt/libSceIcu.md
PR 14144 docs/dev/debt/libSceIcu.md
PR 14340 docs/dev/debt/libSceIcu.md
PR 14443 docs/dev/debt/libSceIcu.md
PR 16250 docs/dev/debt/libSceIcu.md
PR 16971 docs/dev/debt/libSceIcu.md
PR 17297 docs/dev/debt/libSceIcu.md
PR 18208 docs/dev/debt/libSceIcu.md
PR 18210 docs/dev/debt/libSceIcu.md
PR 19435 docs/dev/debt/libSceIcu.md
PR 19951 docs/dev/debt/libSceIcu.md
PR 19972 docs/dev/debt/libSceIcu.md
PR 19985 docs/dev/debt/libSceIcu.md
PR 19998 docs/dev/debt/libSceIcu.md

@roboterspinne
roboterspinne deleted the fix/libsceicu-null-locale-getters branch November 15, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants