feat(libSceIcu): implement escape decoding #10961

Merged
AZLisme merged 4 commits from upstream-pr/10961 into main 2026-10-27 08:16:59 +00:00
AZLisme commented 2026-10-25 11:21:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AZLisme on 2026-10-25T11:21:46Z.


What

Implement u_unescape and u_unescapeAt: numeric, octal, ANSI, control and generic escapes; UTF-16 surrogate joining; guest-ABI callbacks and offset updates; preflight, bounded writes and malformed-input handling. Preserve the reference implementation's eight-digit braced-hex rejection despite its public-header wording.

Contracts follow pinned ICU 78.1 ustring.cpp and ustring.h. Names and NIDs match the pinned PS5 3.20 inventory. Escape behavior and ABI on console hardware remain unverified; firmware availability/routing and invalid-input and size limits remain in debt. No new dependency is added.

Typed declarations are reachable through libSceIcu.hpp; source and tests use those canonical declarations. The branch is rebased onto frozen main 6733079b2d01bb25aa1e6e771680da6a17363e3b, which contains the actual #11013 merge bd1b31548c4f8a21de87b3856b881083ca80492a. All merged invariant/version implementations, canonical declarations, test registrations and debt are preserved alongside the escape-decoding topic.

BunnyFl’s firmware 13.42 report records u_getVersion returning 78.1.0.0 with system_ex/common_ex/lib/libSceIcu.sprx executed under an emulator. Neither u_unescape nor u_unescapeAt is among the checked native module’s 299 exports; only 104 of the 661 NIDs in the older 3.20 inventory match that export table. These older-inventory compatibility APIs remain implemented. Availability and routing across firmware versions, and escape-function behavior on console hardware, are not established by this report.

The extended landing order is agreed: #11013 → #10961 → #10962 → #10963 → #10964 → #10965 → #10966 → #10967 → #11088. The later numeric topic declares #10967; this PR retains #11013 as fulfilled integration history after its merge. All implementations, source/test registrations and updated firmware debt must survive the successive rebases.

Tested

Manual CI 40445885976, attempt 1, completed successfully for the ordered five-PR composition #11472 6e97111223 → #10975 78cb208c0c → #11269 4ccb760d12 → #10950 5746326efc → #10961 844e39236f, on frozen main 09f9a63f6b85aec9f36ce5d0d46f41c37cbd86fd. This PR’s tested head is 844e39236f0ea90203751894aad259bbc703748a.

Release library job Passed Policy-approved skips Failed
Linux 121997011318 2,364 95 0
Windows 121997011314 1,745 825 0

Both jobs passed guest_jsc_string, guest_icu_unescape, guest_icu_version, all 65 public-header CTests and patched_libraries; both skip validators passed. This qualifies the recorded five-PR Linux/Windows Release composition, not either PR alone or later main. Ancillary macOS/relinker-ASan jobs do not establish macOS-library, library-ASan or native-console coverage. The declared #11013 predecessor and agreed ICU landing/integration order remain unchanged. Earlier entries below retain their original heads, compositions, outcomes and historical status.

Maintainer CI 40382857757/a1 has mixed results; the full run failed on Linux. Exact composition: base 6b16c9c6499a, then #10961@844e39236f0e → #10953@8b4bb4d239ad → #11235@3e333ce0fc5d → #11337@d84c522f4bda → #10950@5746326efc33.

Windows job 121783493660 passed its normal Release build/library targets and suite: 1,692 passed, 815 validated expected skips, zero failed / 2,507. Linux job 121783493789 built successfully but reported 2,306 passed, 93 observed skips, two failed / 2,401: guest_sigvec_modules and guest_posix_spawn. Its skip validator was skipped; those 93 skips are not policy-qualified.

On both platforms, guest_icu_version and guest_icu_unescape and all 65 header cases (public_headers plus 64 compilation batches) passed. This qualifies only the exact five-input composition, not an isolated head, newer main, other ICU follower heads, console equivalence or an overall green run. No source changes or dependency waivers result from this evidence. Existing prerequisite and review gates remain. Earlier entries below retain their historical source/base scopes.

Current preserving-rebase head 844e39236f0ea90203751894aad259bbc703748a is clean on 6733079b2d01bb25aa1e6e771680da6a17363e3b. The decoder implementation, canonical escape header and full escape test are byte-identical to published 7010784ecedd722126d727a277b26ec9778a70f1; upstream #11013 implementation/header/version-test bytes and debt are preserved. Both runtime test registrations survive. git diff --check and python3 tools/check_conventions.py --base origin/main passed. Fresh exact-head validation for 844e39236f0ea90203751894aad259bbc703748a on frozen base 6733079b2d01bb25aa1e6e771680da6a17363e3b: Linux x86-64, GNU 16.2.1, Release, BUILD_TESTING=ON. The complete ICU module and every registered fixture were freshly built through the actual library CMake and original root helper bodies. guest_icu_version, guest_icu_unescape passed 2/2, with zero failures or skips; this includes the inherited #11013 version test and every owned topic fixture. All five C++ header units passed, covering standalone/repeated inclusion, the umbrella and composition with libc/kernel. The declaration audit was run on this exact selected source tree.

The common libc/kernel runtime was freshly built once from that approved base and reused for this independent provider only after all 258 actual core project inputs, normal CMake/helper bodies, copied artifact hashes and provider paths were qualified against this head. Pinned source-built ZArchive/zstd archives were reused after source/hash/pin checks. This validates this independent ICU provider; it is not a seven-topic composite or a fresh core rebuild per branch.

Current validation is Linux component evidence. No new native Windows, macOS, PS5, sanitizer, full-product or GPU result is claimed; Windows-only HostWrite-refusal paths were not executed by this Linux lane. Earlier platform, maintainer CI, firmware and private-integration evidence below retains its original head/base scope and does not qualify this rebased head.

Historical validation, retained with its original source/base scope:

Documentation follow-up 7010784ecedd722126d727a277b26ec9778a70f1 records the firmware evidence only. The complete core/libs tree (production code, public headers, CMake and tests) is byte-identical to published 524ad73c3ebeea131638d6a8cd908e6992e7fdb8. Conventions and whitespace checks passed for the new documentation head. Existing runtime and header results below are reused from unchanged executable sources; no build, runtime rerun or header compilation was needed for this documentation change.

Linux x86-64, GCC 16.2.1, Release, BUILD_TESTING=ON. Built the complete changed ICU PRX through its actual library CMake, linked to the freshly rebuilt libc/kernel runtime from the same frozen base. guest_icu_unescape passed, 1/1. Escape forms, malformed/truncated input, surrogate joining, seven exact callback-order/visible-offset probes (including indices near INT32_MAX), bounded UTF-16 prefixes and split-pair canaries, preflight lengths, and nonzero terminator sentinels. The earlier review follow-up changed tests only; production decoder source is unchanged.

The repository-wide public_headers audit passed, and the canonical declaration header plus umbrella compiled independently with -Werror. python3 tools/check_conventions.py --base origin/main and git diff --check passed for head 524ad73c3ebeea131638d6a8cd908e6992e7fdb8. Validation covered the changed library and its runtime dependencies on Linux; Windows, macOS and console execution were not performed.

#11013 has merged. Its five distinct invariant/version helpers are preserved in this rebase, including their source/header files, guest_icu_version registration and debt. The agreed landing order remains #11013 first, then this PR and #10962–#10967, extended by #11088 as linked above. #11013 is a fulfilled integration predecessor; this ordering coordinates shared files and the APIs remain functionally independent.
Existing pinned Linux integration evidence on base 3a2c51afd2 combines #11013 head 0fd2e0ce9fb870713022b1f2a369fb6b1ff28366 with the seven ICU topic heads, including UTF alias correction 58c283d6890d6faaeeb1ec5bd5fd17908ee1093b. The actual complete ICU library build and 10/10 runtime tests pass with zero skips; all 42 unique public exports are present. All 19 current input production/test sources and all eight registration blocks are preserved. The full public-header audit and 11 composition checks pass, including all 368 library umbrellas together. This validates the concrete mechanical merge sequence and is reused for the documentation update; it is not a new Windows or console run.

Additional nine-topic Linux validation combines #11013 37d5137ea0, #11088 a43b228a4a input bytes and the current seven-topic series, including UTF alias fix 58c283d689. The private normal-library build passed 11/11 runtime tests, retains 66 public exports, and passes 12 header-composition checks. The numeric test at a43 is byte-identical to the portability-corrected test that was compiled; its production/API/CMake inputs are unchanged. This evidence reuses the exact compiled input bytes, with frozen base 5949d8bf and the explicitly qualified #10953 core composite from that base, rather than a pure-main or Windows combined run. The earlier unmodified numeric test at 2098426fbf failed on LP64; that historical failure is superseded by a43’s applied test fix.

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: #11013
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5004250801 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10961). Originally posted by [AZLisme](https://github.com/AZLisme) on 2026-10-25T11:21:46Z. --- ### What Implement `u_unescape` and `u_unescapeAt`: numeric, octal, ANSI, control and generic escapes; UTF-16 surrogate joining; guest-ABI callbacks and offset updates; preflight, bounded writes and malformed-input handling. Preserve the reference implementation's eight-digit braced-hex rejection despite its public-header wording. Contracts follow pinned [ICU 78.1 ustring.cpp](https://github.com/unicode-org/icu/blob/049e0d6a420629ac7db77256987d083a563287b5/icu4c/source/common/ustring.cpp) and [ustring.h](https://github.com/unicode-org/icu/blob/049e0d6a420629ac7db77256987d083a563287b5/icu4c/source/common/unicode/ustring.h). Names and NIDs match the pinned [PS5 3.20 inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceIcu.c). Escape behavior and ABI on console hardware remain unverified; firmware availability/routing and invalid-input and size limits remain in debt. No new dependency is added. Typed declarations are reachable through `libSceIcu.hpp`; source and tests use those canonical declarations. The branch is rebased onto frozen main `6733079b2d01bb25aa1e6e771680da6a17363e3b`, which contains the actual #11013 merge `bd1b31548c4f8a21de87b3856b881083ca80492a`. All merged invariant/version implementations, canonical declarations, test registrations and debt are preserved alongside the escape-decoding topic. [BunnyFl’s firmware 13.42 report](https://github.com/boykopovar/AnyPS5/pull/10961#issuecomment-6400071863) records `u_getVersion` returning `78.1.0.0` with `system_ex/common_ex/lib/libSceIcu.sprx` executed under an emulator. Neither `u_unescape` nor `u_unescapeAt` is among the checked native module’s 299 exports; only 104 of the 661 NIDs in the older 3.20 inventory match that export table. These older-inventory compatibility APIs remain implemented. Availability and routing across firmware versions, and escape-function behavior on console hardware, are not established by this report. The [extended landing order is agreed](https://github.com/boykopovar/AnyPS5/pull/11088#issuecomment-6401505606): #11013 → #10961 → #10962 → #10963 → #10964 → #10965 → #10966 → #10967 → #11088. The later numeric topic declares #10967; this PR retains #11013 as fulfilled integration history after its merge. All implementations, source/test registrations and updated firmware debt must survive the successive rebases. ### Tested [Manual CI `40445885976`](https://github.com/boykopovar/AnyPS5/actions/runs/40445885976), attempt 1, completed successfully for the **ordered five-PR composition** #11472 `6e97111223` → #10975 `78cb208c0c` → #11269 `4ccb760d12` → #10950 `5746326efc` → #10961 `844e39236f`, on frozen main `09f9a63f6b85aec9f36ce5d0d46f41c37cbd86fd`. This PR’s tested head is `844e39236f0ea90203751894aad259bbc703748a`. | Release library job | Passed | Policy-approved skips | Failed | |---|---:|---:|---:| | [Linux `121997011318`](https://github.com/boykopovar/AnyPS5/actions/runs/40445885976/job/121997011318) | 2,364 | 95 | 0 | | [Windows `121997011314`](https://github.com/boykopovar/AnyPS5/actions/runs/40445885976/job/121997011314) | 1,745 | 825 | 0 | Both jobs passed `guest_jsc_string`, `guest_icu_unescape`, `guest_icu_version`, all 65 public-header CTests and `patched_libraries`; both skip validators passed. This qualifies the recorded five-PR Linux/Windows Release composition, not either PR alone or later main. Ancillary macOS/relinker-ASan jobs do not establish macOS-library, library-ASan or native-console coverage. The declared #11013 predecessor and agreed ICU landing/integration order remain unchanged. Earlier entries below retain their original heads, compositions, outcomes and historical status. [Maintainer CI 40382857757/a1](https://github.com/boykopovar/AnyPS5/actions/runs/40382857757) has mixed results; **the full run failed on Linux**. Exact composition: base `6b16c9c6499a`, then #10961@`844e39236f0e` → #10953@`8b4bb4d239ad` → #11235@`3e333ce0fc5d` → #11337@`d84c522f4bda` → #10950@`5746326efc33`. [Windows job 121783493660](https://github.com/boykopovar/AnyPS5/actions/runs/40382857757/job/121783493660) passed its normal Release build/library targets and suite: **1,692 passed, 815 validated expected skips, zero failed / 2,507**. [Linux job 121783493789](https://github.com/boykopovar/AnyPS5/actions/runs/40382857757/job/121783493789) built successfully but reported **2,306 passed, 93 observed skips, two failed / 2,401**: `guest_sigvec_modules` and `guest_posix_spawn`. Its skip validator was skipped; those 93 skips are not policy-qualified. On both platforms, `guest_icu_version` and `guest_icu_unescape` and all 65 header cases (`public_headers` plus 64 compilation batches) passed. This qualifies only the exact five-input composition, not an isolated head, newer main, other ICU follower heads, console equivalence or an overall green run. No source changes or dependency waivers result from this evidence. Existing prerequisite and review gates remain. Earlier entries below retain their historical source/base scopes. Current preserving-rebase head `844e39236f0ea90203751894aad259bbc703748a` is clean on `6733079b2d01bb25aa1e6e771680da6a17363e3b`. The decoder implementation, canonical escape header and full escape test are byte-identical to published `7010784ecedd722126d727a277b26ec9778a70f1`; upstream #11013 implementation/header/version-test bytes and debt are preserved. Both runtime test registrations survive. `git diff --check` and `python3 tools/check_conventions.py --base origin/main` passed. Fresh exact-head validation for `844e39236f0ea90203751894aad259bbc703748a` on frozen base `6733079b2d01bb25aa1e6e771680da6a17363e3b`: Linux x86-64, GNU 16.2.1, Release, `BUILD_TESTING=ON`. The complete ICU module and every registered fixture were freshly built through the actual library CMake and original root helper bodies. `guest_icu_version`, `guest_icu_unescape` passed **2/2**, with zero failures or skips; this includes the inherited #11013 version test and every owned topic fixture. All five C++ header units passed, covering standalone/repeated inclusion, the umbrella and composition with libc/kernel. The declaration audit was run on this exact selected source tree. The common libc/kernel runtime was freshly built once from that approved base and reused for this independent provider only after all 258 actual core project inputs, normal CMake/helper bodies, copied artifact hashes and provider paths were qualified against this head. Pinned source-built ZArchive/zstd archives were reused after source/hash/pin checks. This validates this independent ICU provider; it is not a seven-topic composite or a fresh core rebuild per branch. Current validation is Linux component evidence. No new native Windows, macOS, PS5, sanitizer, full-product or GPU result is claimed; Windows-only HostWrite-refusal paths were not executed by this Linux lane. Earlier platform, maintainer CI, firmware and private-integration evidence below retains its original head/base scope and does not qualify this rebased head. Historical validation, retained with its original source/base scope: Documentation follow-up `7010784ecedd722126d727a277b26ec9778a70f1` records the firmware evidence only. The complete `core/libs` tree (production code, public headers, CMake and tests) is byte-identical to published `524ad73c3ebeea131638d6a8cd908e6992e7fdb8`. Conventions and whitespace checks passed for the new documentation head. Existing runtime and header results below are reused from unchanged executable sources; no build, runtime rerun or header compilation was needed for this documentation change. Linux x86-64, GCC 16.2.1, Release, `BUILD_TESTING=ON`. Built the complete changed ICU PRX through its actual library CMake, linked to the freshly rebuilt libc/kernel runtime from the same frozen base. `guest_icu_unescape` passed, 1/1. Escape forms, malformed/truncated input, surrogate joining, seven exact callback-order/visible-offset probes (including indices near INT32_MAX), bounded UTF-16 prefixes and split-pair canaries, preflight lengths, and nonzero terminator sentinels. The earlier review follow-up changed tests only; production decoder source is unchanged. The repository-wide `public_headers` audit passed, and the canonical declaration header plus umbrella compiled independently with `-Werror`. `python3 tools/check_conventions.py --base origin/main` and `git diff --check` passed for head `524ad73c3ebeea131638d6a8cd908e6992e7fdb8`. Validation covered the changed library and its runtime dependencies on Linux; Windows, macOS and console execution were not performed. #11013 has merged. Its five distinct invariant/version helpers are preserved in this rebase, including their source/header files, `guest_icu_version` registration and debt. The [agreed landing order](https://github.com/boykopovar/AnyPS5/pull/11013#issuecomment-6400134113) remains #11013 first, then this PR and #10962–#10967, extended by #11088 as linked above. #11013 is a fulfilled integration predecessor; this ordering coordinates shared files and the APIs remain functionally independent. Existing pinned Linux integration evidence on base `3a2c51afd2` combines #11013 head `0fd2e0ce9fb870713022b1f2a369fb6b1ff28366` with the seven ICU topic heads, including UTF alias correction `58c283d6890d6faaeeb1ec5bd5fd17908ee1093b`. The actual complete ICU library build and **10/10 runtime tests** pass with zero skips; all **42 unique public exports** are present. All 19 current input production/test sources and all eight registration blocks are preserved. The full public-header audit and 11 composition checks pass, including all 368 library umbrellas together. This validates the concrete mechanical merge sequence and is reused for the documentation update; it is not a new Windows or console run. Additional nine-topic Linux validation combines #11013 `37d5137ea0`, #11088 `a43b228a4a` input bytes and the current seven-topic series, including UTF alias fix `58c283d689`. The private normal-library build passed 11/11 runtime tests, retains 66 public exports, and passes 12 header-composition checks. The numeric test at a43 is byte-identical to the portability-corrected test that was compiled; its production/API/CMake inputs are unchanged. This evidence reuses the exact compiled input bytes, with frozen base `5949d8bf` and the explicitly qualified #10953 core composite from that base, rather than a pure-main or Windows combined run. The earlier unmodified numeric test at `2098426fbf` failed on LP64; that historical failure is superseded by a43’s applied test fix. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/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: <!-- #PR, or none --> #11013 - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
thepoppfish commented 2026-10-25 11:41:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T11:41:52Z.

Review: APPROVED


Reviewed exact head 8f40cf8e9f2b1a73c76492245146b3380e4e6248; no blocking findings. I compared the decoder with the pinned ICU 78.1 implementation, including offset restoration, lookahead through a local offset and the eight-digit braced-hex behavior. Console-version equivalence remains explicitly unverified in debt.

Independent Windows 11 build 26200, MSYS2 UCRT64 GCC 16.2.0-6, CMake 4.3.1, Ninja 1.13.2, Release validation, adding the platform absent from the author's report:

  • Built the complete changed ICU library (Export.cpp and Unescape.cpp) through its actual library CMake and ran the complete unmodified tests/Unescape.cpp across the resulting .prx DLL. Used the exact production add_test_executable/configure_windows_unwind helpers and WindowsTestExit.cpp. No LTO, decoder replacement or test-body edit.
  • Focused parent harness supplies only NotImplemented_nid_no_patch, with the same std::runtime_error(std::string(name) + " not implemented") body as General.cpp. Full libc/kernel were not linked, so this is an isolated native library test, not a full runtime build.
  • Complete submitted test passes (0.03 s in final run). An additional cross-DLL probe passes seven guest-ABI callback cases: observed call order and the caller-visible offset, numeric/braced escapes, malformed input, recursive surrogate lookahead, failed lookahead and indices near INT32_MAX. Both registered tests pass, 0.12 s total.
  • Mutation control changes only characterAt(position++, context) to call the callback before incrementing. The complete submitted fixture still passes, while the additional probe fails at its visible-offset/order assertion. This is a scratch mutation, not an upstream failing baseline. The PR code itself is correct here; the probe would be useful extra regression coverage for the behavior described in the PR.
  • python core/libs/tests/test_public_headers.py --audit-only: 368 libraries, 12,190 exports, unique declarations and umbrella coverage verified. Canonical API and umbrella headers compile together, twice included, with GCC -Werror -fsyntax-only.
  • Conventions and whitespace pass against fetched main 16ff208dc32cf3927ba1bae492eee363a5ae7ae8. Tree-only merge is clean (tree 9c903fdf181eb84cca80fc2d1decdb98a5efa6f8); no merged-tree test run claimed.

No PS5/title/GPU execution, NID-patched artifact execution, full product/runtime build, Linux/macOS run or hosted workflow claim. The author checkout remains clean and unchanged. AI-assisted review/testing: yes, OpenAI Codex.

Windows harness and additional callback probe replay

Save these files in a separate directory. Extract the unchanged add_test_executable function from the pinned checkout's top-level CMakeLists.txt and configure_windows_unwind from core/libs/CMakeLists.txt into ProductionHelpers.cmake. The supplied callback probe is additional coverage; the PR's full test source is read directly from the pinned checkout.

cmake -S <harness> -B <harness>/build -G Ninja -DCMAKE_BUILD_TYPE=Release -DICU_REPO=<checkout>
cmake --build <harness>/build
ctest --test-dir <harness>/build --output-on-failure -V

For the control, save a copy of the decoder outside the checkout, replacing only const auto initial = characterAt(position++, context); with const auto initial = characterAt(position, context); ++position;. Configure a separate build with -DICU_UNESCAPE_SOURCE=<control.cpp>. Expect the additional callback test to fail and the submitted test to pass. Keep the GCC runtime DLL directory on PATH for both runs.

CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
project(IcuUnescapeReview LANGUAGES CXX)
enable_testing()
set(CMAKE_CXX_STANDARD 20)
get_filename_component(ICU_DEFAULT_REPO "${CMAKE_CURRENT_SOURCE_DIR}/../review-10961" ABSOLUTE)
set(ICU_REPO "${ICU_DEFAULT_REPO}" CACHE PATH "Exact PR checkout")
set(LIBS_INCLUDE_DIR "${ICU_REPO}/core/libs")
set(BUILD_TESTING ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
include("${CMAKE_CURRENT_SOURCE_DIR}/ProductionHelpers.cmake")
add_library(anyps5_windows_test_exit OBJECT "${ICU_REPO}/cmake/WindowsTestExit.cpp")
add_subdirectory("${ICU_REPO}/core/libs/prx/libSceIcu" icu)
set(ICU_UNESCAPE_SOURCE "" CACHE FILEPATH "Optional scratch decoder control")
if(ICU_UNESCAPE_SOURCE)
    get_target_property(ICU_SOURCES libSceIcu SOURCES)
    list(REMOVE_ITEM ICU_SOURCES "${ICU_REPO}/core/libs/prx/libSceIcu/Unescape.cpp")
    set_property(TARGET libSceIcu PROPERTY SOURCES ${ICU_SOURCES} "${ICU_UNESCAPE_SOURCE}")
endif()
target_sources(libSceIcu PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Support.cpp")
set_target_properties(libSceIcu PROPERTIES PREFIX "" SUFFIX ".prx")
add_test_executable(icu_callback_probe CallbackProbe.cpp)
target_include_directories(icu_callback_probe PRIVATE "${LIBS_INCLUDE_DIR}")
target_link_libraries(icu_callback_probe PRIVATE libSceIcu)
configure_windows_unwind(icu_callback_probe)
add_test(NAME icu_callback_probe COMMAND icu_callback_probe)
set_tests_properties(icu_callback_probe PROPERTIES TIMEOUT 10 ENVIRONMENT_MODIFICATION
    "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceIcu>")

Support.cpp

#include "prx/libc/include/General.hpp"
#include <stdexcept>
#include <string>

extern "C" [[noreturn]] void NotImplemented_nid_no_patch(const char* name) {
    throw std::runtime_error(std::string(name) + " not implemented");
}

CallbackProbe.cpp

#include "prx/libSceIcu/libSceIcu.hpp"
#include <cstdint>
#include <cstdio>
#include <limits>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>

namespace {
using Observation = std::pair<std::int32_t, std::int32_t>;
struct State {
    std::u16string text;
    std::int32_t base;
    std::int32_t* offset;
    std::vector<Observation> observed;
};
char16_t APS5_VABI Read(std::int32_t index, void* context) {
    auto& state = *static_cast<State*>(context);
    state.observed.emplace_back(index - state.base, *state.offset - state.base);
    const auto relative = static_cast<std::int64_t>(index) - state.base;
    if (relative < 0 || relative >= static_cast<std::int64_t>(state.text.size()))
        throw std::runtime_error("callback read outside declared text");
    return state.text[static_cast<std::size_t>(relative)];
}
void Check(std::u16string text, std::int32_t expected, std::int32_t consumed,
           std::vector<Observation> observations, std::int32_t base = 0) {
    std::int32_t offset = base;
    State state{std::move(text), base, &offset, {}};
    const auto length = static_cast<std::int32_t>(static_cast<std::int64_t>(base) + state.text.size());
    const auto result = u_unescapeAt_nid_postfix(Read, &offset, length, &state);
    if (result != expected || offset - base != consumed || state.observed != observations)
        throw std::runtime_error("callback value, visible offsets or order differs");
}
}

int main() {
    try {
    Check(u"u0041!", 0x41, 5, {{0,1},{1,1},{2,2},{3,3},{4,4}});
    Check(u"x{41}", 0x41, 5, {{0,1},{1,1},{2,2},{3,3},{4,4}});
    Check(u"u12", -1, 0, {{0,1},{1,1},{2,2}});
    Check(u"uD83D\\uDE00", 0x1f600, 11,
          {{0,1},{1,1},{2,2},{3,3},{4,4},{5,5},{6,5},{7,5},{8,5},{9,5},{10,5}});
    Check(u"uD800\\u12", 0xd800, 5,
          {{0,1},{1,1},{2,2},{3,3},{4,4},{5,5},{6,5},{7,5},{8,5}});
    Check(std::u16string(u"uD83D") + char16_t{0xde00}, 0x1f600, 6,
          {{0,1},{1,1},{2,2},{3,3},{4,4},{5,5}}, std::numeric_limits<std::int32_t>::max() - 6);
    Check(u"u", -1, 0, {{0,1}}, std::numeric_limits<std::int32_t>::max() - 1);
    std::puts("Seven cross-DLL guest callback order/visible-offset/boundary cases pass");
    } catch (const std::exception& error) {
        std::fprintf(stderr, "%s\n", error.what());
        return 1;
    }
}

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643026908 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10961#pullrequestreview-5643026908). Originally posted by [thepoppfish](https://github.com/thepoppfish) on 2026-10-25T11:41:52Z. **Review:** APPROVED --- Reviewed exact head `8f40cf8e9f2b1a73c76492245146b3380e4e6248`; no blocking findings. I compared the decoder with the pinned [ICU 78.1 implementation](https://github.com/unicode-org/icu/blob/049e0d6a420629ac7db77256987d083a563287b5/icu4c/source/common/ustring.cpp#L1133-L1343), including offset restoration, lookahead through a local offset and the eight-digit braced-hex behavior. Console-version equivalence remains explicitly unverified in debt. Independent Windows 11 build 26200, MSYS2 UCRT64 GCC 16.2.0-6, CMake 4.3.1, Ninja 1.13.2, Release validation, adding the platform absent from the author's report: - Built the complete changed ICU library (`Export.cpp` and `Unescape.cpp`) through its actual library CMake and ran the complete unmodified `tests/Unescape.cpp` across the resulting `.prx` DLL. Used the exact production `add_test_executable`/`configure_windows_unwind` helpers and `WindowsTestExit.cpp`. No LTO, decoder replacement or test-body edit. - Focused parent harness supplies only `NotImplemented_nid_no_patch`, with the same `std::runtime_error(std::string(name) + " not implemented")` body as `General.cpp`. Full libc/kernel were not linked, so this is an isolated native library test, not a full runtime build. - Complete submitted test passes (0.03 s in final run). An additional cross-DLL probe passes seven guest-ABI callback cases: observed call order and the caller-visible offset, numeric/braced escapes, malformed input, recursive surrogate lookahead, failed lookahead and indices near `INT32_MAX`. Both registered tests pass, 0.12 s total. - Mutation control changes only `characterAt(position++, context)` to call the callback before incrementing. The complete submitted fixture still passes, while the additional probe fails at its visible-offset/order assertion. This is a scratch mutation, not an upstream failing baseline. The PR code itself is correct here; the probe would be useful extra regression coverage for the behavior described in the PR. - `python core/libs/tests/test_public_headers.py --audit-only`: 368 libraries, 12,190 exports, unique declarations and umbrella coverage verified. Canonical API and umbrella headers compile together, twice included, with GCC `-Werror -fsyntax-only`. - Conventions and whitespace pass against fetched main `16ff208dc32cf3927ba1bae492eee363a5ae7ae8`. Tree-only merge is clean (tree `9c903fdf181eb84cca80fc2d1decdb98a5efa6f8`); no merged-tree test run claimed. No PS5/title/GPU execution, NID-patched artifact execution, full product/runtime build, Linux/macOS run or hosted workflow claim. The author checkout remains clean and unchanged. AI-assisted review/testing: yes, OpenAI Codex. <details><summary>Windows harness and additional callback probe replay</summary> Save these files in a separate directory. Extract the unchanged `add_test_executable` function from the pinned checkout's top-level `CMakeLists.txt` and `configure_windows_unwind` from `core/libs/CMakeLists.txt` into `ProductionHelpers.cmake`. The supplied callback probe is additional coverage; the PR's full test source is read directly from the pinned checkout. ```text cmake -S <harness> -B <harness>/build -G Ninja -DCMAKE_BUILD_TYPE=Release -DICU_REPO=<checkout> cmake --build <harness>/build ctest --test-dir <harness>/build --output-on-failure -V ``` For the control, save a copy of the decoder outside the checkout, replacing only `const auto initial = characterAt(position++, context);` with `const auto initial = characterAt(position, context); ++position;`. Configure a separate build with `-DICU_UNESCAPE_SOURCE=<control.cpp>`. Expect the additional callback test to fail and the submitted test to pass. Keep the GCC runtime DLL directory on PATH for both runs. `CMakeLists.txt` ```cmake cmake_minimum_required(VERSION 3.20) project(IcuUnescapeReview LANGUAGES CXX) enable_testing() set(CMAKE_CXX_STANDARD 20) get_filename_component(ICU_DEFAULT_REPO "${CMAKE_CURRENT_SOURCE_DIR}/../review-10961" ABSOLUTE) set(ICU_REPO "${ICU_DEFAULT_REPO}" CACHE PATH "Exact PR checkout") set(LIBS_INCLUDE_DIR "${ICU_REPO}/core/libs") set(BUILD_TESTING ON) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) include("${CMAKE_CURRENT_SOURCE_DIR}/ProductionHelpers.cmake") add_library(anyps5_windows_test_exit OBJECT "${ICU_REPO}/cmake/WindowsTestExit.cpp") add_subdirectory("${ICU_REPO}/core/libs/prx/libSceIcu" icu) set(ICU_UNESCAPE_SOURCE "" CACHE FILEPATH "Optional scratch decoder control") if(ICU_UNESCAPE_SOURCE) get_target_property(ICU_SOURCES libSceIcu SOURCES) list(REMOVE_ITEM ICU_SOURCES "${ICU_REPO}/core/libs/prx/libSceIcu/Unescape.cpp") set_property(TARGET libSceIcu PROPERTY SOURCES ${ICU_SOURCES} "${ICU_UNESCAPE_SOURCE}") endif() target_sources(libSceIcu PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Support.cpp") set_target_properties(libSceIcu PROPERTIES PREFIX "" SUFFIX ".prx") add_test_executable(icu_callback_probe CallbackProbe.cpp) target_include_directories(icu_callback_probe PRIVATE "${LIBS_INCLUDE_DIR}") target_link_libraries(icu_callback_probe PRIVATE libSceIcu) configure_windows_unwind(icu_callback_probe) add_test(NAME icu_callback_probe COMMAND icu_callback_probe) set_tests_properties(icu_callback_probe PROPERTIES TIMEOUT 10 ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceIcu>") ``` `Support.cpp` ```cpp #include "prx/libc/include/General.hpp" #include <stdexcept> #include <string> extern "C" [[noreturn]] void NotImplemented_nid_no_patch(const char* name) { throw std::runtime_error(std::string(name) + " not implemented"); } ``` `CallbackProbe.cpp` ```cpp #include "prx/libSceIcu/libSceIcu.hpp" #include <cstdint> #include <cstdio> #include <limits> #include <stdexcept> #include <string> #include <utility> #include <vector> namespace { using Observation = std::pair<std::int32_t, std::int32_t>; struct State { std::u16string text; std::int32_t base; std::int32_t* offset; std::vector<Observation> observed; }; char16_t APS5_VABI Read(std::int32_t index, void* context) { auto& state = *static_cast<State*>(context); state.observed.emplace_back(index - state.base, *state.offset - state.base); const auto relative = static_cast<std::int64_t>(index) - state.base; if (relative < 0 || relative >= static_cast<std::int64_t>(state.text.size())) throw std::runtime_error("callback read outside declared text"); return state.text[static_cast<std::size_t>(relative)]; } void Check(std::u16string text, std::int32_t expected, std::int32_t consumed, std::vector<Observation> observations, std::int32_t base = 0) { std::int32_t offset = base; State state{std::move(text), base, &offset, {}}; const auto length = static_cast<std::int32_t>(static_cast<std::int64_t>(base) + state.text.size()); const auto result = u_unescapeAt_nid_postfix(Read, &offset, length, &state); if (result != expected || offset - base != consumed || state.observed != observations) throw std::runtime_error("callback value, visible offsets or order differs"); } } int main() { try { Check(u"u0041!", 0x41, 5, {{0,1},{1,1},{2,2},{3,3},{4,4}}); Check(u"x{41}", 0x41, 5, {{0,1},{1,1},{2,2},{3,3},{4,4}}); Check(u"u12", -1, 0, {{0,1},{1,1},{2,2}}); Check(u"uD83D\\uDE00", 0x1f600, 11, {{0,1},{1,1},{2,2},{3,3},{4,4},{5,5},{6,5},{7,5},{8,5},{9,5},{10,5}}); Check(u"uD800\\u12", 0xd800, 5, {{0,1},{1,1},{2,2},{3,3},{4,4},{5,5},{6,5},{7,5},{8,5}}); Check(std::u16string(u"uD83D") + char16_t{0xde00}, 0x1f600, 6, {{0,1},{1,1},{2,2},{3,3},{4,4},{5,5}}, std::numeric_limits<std::int32_t>::max() - 6); Check(u"u", -1, 0, {{0,1}}, std::numeric_limits<std::int32_t>::max() - 1); std::puts("Seven cross-DLL guest callback order/visible-offset/boundary cases pass"); } catch (const std::exception& error) { std::fprintf(stderr, "%s\n", error.what()); return 1; } } ``` </details>
ahmadmuj commented 2026-10-25 12:09:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T12:09:27Z.

Review: APPROVED


Reviewed head 8f40cf8e9f2b1a73c76492245146b3380e4e6248, merged locally onto main a5a780eaaa7f187fe8f5c7f2ef244f6a6dab2762 (clean).

What I ran, Linux x86-64, GCC 13.3:

  • Merged tree, full configure with BUILD_TESTING=ON, built guest_icu_unescape_tests only: guest_icu_unescape passes 1/1. check_conventions.py --base origin/main passes.
  • A differential harness. It runs your Unescape.cpp unmodified against two references: the u_unescapeAt/u_unescape text copied verbatim from the pinned ICU 78.1 ustring.cpp (L1168-1429, only the macros shimmed), and the real system libicuuc.so.74 (ICU 74.2). It compares the return value, the final *offset, the full callback trace (index plus the *offset the callback sees), and for u_unescape a sentinel-filled buffer at every capacity from 0 to len+3, plus null dest.
    • Exhaustive inputs up to 7 units over an escape-heavy alphabet (\ u U x { } c 0 7 8 D d F A n C, plus D83D/DE00 for u_unescapeAt and 0xE9 for u_unescape), with start offsets INT32_MIN, -1, every index up to len+1, and INT32_MAX, and every truncated length.
    • Structured cases: 0-10 digit \u/\U/\x{}, the 10FFFF/110000/FFFFFFFF bounds, lead escapes times 37 tail forms (including \x{0000DFFF}), lead chains, and \c.
    • 110M random strings.
    • About 59.7 billion compared cases in total, 0 mismatches between any pair in those sets, 0 sanitizer reports in your code (ASan+UBSan on the length-6, structured and 10M random sets).
    • Two scratch mutants (tail limit 11 to 12, and no dest[0] = 0 on error) were both caught, so the harness does see these paths.
  • The only difference I found is in a separate run at callback indices within 11 of INT32_MAX. ICU computes ahead + 11 there (ustring.cpp L1299), which is signed overflow, and UBSan flags it. Your std::min version is defined. So that is fine and needs no debt line.
  • ICU 78.1 and 74.2 agreed on every case, the high-offset one included.
  • Negative capacity with a nonnull dest: both ICU versions return the full length and write nothing. Your debt entry already covers the throw.

Approving. Some small test notes, none blocking:

  • tests/Unescape.cpp:142: std::array<char16_t, 3> output{} starts zeroed, so output[1] == 0 / output[2] == 0 can't fail if the terminator write goes missing. Filling it with 0xa55a first would make those checks real.
  • tests/Unescape.cpp:101: for capacity < expected.size() the test only checks the tail sentinels, not the truncated prefix. For example, String("A\\u0042", u"AB") at capacity 1 never asserts output[1] == u'A'.
  • positions (L37) records the reads but only its size is checked. The callback-order probe in the earlier review would cover this.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643143114 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10961#pullrequestreview-5643143114). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T12:09:27Z. **Review:** APPROVED --- Reviewed head `8f40cf8e9f2b1a73c76492245146b3380e4e6248`, merged locally onto main `a5a780eaaa7f187fe8f5c7f2ef244f6a6dab2762` (clean). What I ran, Linux x86-64, GCC 13.3: - Merged tree, full configure with `BUILD_TESTING=ON`, built `guest_icu_unescape_tests` only: `guest_icu_unescape` passes 1/1. `check_conventions.py --base origin/main` passes. - A differential harness. It runs your `Unescape.cpp` unmodified against two references: the `u_unescapeAt`/`u_unescape` text copied verbatim from the pinned ICU 78.1 `ustring.cpp` (L1168-1429, only the macros shimmed), and the real system `libicuuc.so.74` (ICU 74.2). It compares the return value, the final `*offset`, the full callback trace (index plus the `*offset` the callback sees), and for `u_unescape` a sentinel-filled buffer at every capacity from 0 to len+3, plus null dest. - Exhaustive inputs up to 7 units over an escape-heavy alphabet (`\ u U x { } c 0 7 8 D d F A n C`, plus D83D/DE00 for `u_unescapeAt` and 0xE9 for `u_unescape`), with start offsets INT32_MIN, -1, every index up to len+1, and INT32_MAX, and every truncated `length`. - Structured cases: 0-10 digit `\u`/`\U`/`\x{}`, the 10FFFF/110000/FFFFFFFF bounds, lead escapes times 37 tail forms (including `\x{0000DFFF}`), lead chains, and `\c`. - 110M random strings. - About 59.7 billion compared cases in total, 0 mismatches between any pair in those sets, 0 sanitizer reports in your code (ASan+UBSan on the length-6, structured and 10M random sets). - Two scratch mutants (tail limit 11 to 12, and no `dest[0] = 0` on error) were both caught, so the harness does see these paths. - The only difference I found is in a separate run at callback indices within 11 of INT32_MAX. ICU computes `ahead + 11` there (ustring.cpp L1299), which is signed overflow, and UBSan flags it. Your `std::min` version is defined. So that is fine and needs no debt line. - ICU 78.1 and 74.2 agreed on every case, the high-offset one included. - Negative capacity with a nonnull dest: both ICU versions return the full length and write nothing. Your debt entry already covers the throw. Approving. Some small test notes, none blocking: - `tests/Unescape.cpp:142`: `std::array<char16_t, 3> output{}` starts zeroed, so `output[1] == 0` / `output[2] == 0` can't fail if the terminator write goes missing. Filling it with `0xa55a` first would make those checks real. - `tests/Unescape.cpp:101`: for `capacity < expected.size()` the test only checks the tail sentinels, not the truncated prefix. For example, `String("A\\u0042", u"AB")` at capacity 1 never asserts `output[1] == u'A'`. - `positions` (L37) records the reads but only its size is checked. The callback-order probe in the earlier review would cover this.
MarcZX10 commented 2026-10-25 13:25:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T13:25:02Z.

Review: APPROVED


Re-reviewed exact head 524ad73c3ebeea131638d6a8cd908e6992e7fdb8. The test-only update now checks nonzero terminator sentinels, each output capacity's written prefix and split-surrogate canaries, and callback read order/visible offsets including the INT32_MAX boundary. Production decoding code is unchanged from the previously reviewed implementation.

I ran python3 tools/check_conventions.py --base upstream/main --head HEAD and git diff --check upstream/main...HEAD; both pass. The author reports the ICU library rebuild and focused Linux test passing. Earlier exact-head reviews independently compared the decoder with pinned ICU 78.1 and ran Linux and Windows test builds. Console-version equivalence remains the documented limitation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643378090 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10961#pullrequestreview-5643378090). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T13:25:02Z. **Review:** APPROVED --- Re-reviewed exact head `524ad73c3ebeea131638d6a8cd908e6992e7fdb8`. The test-only update now checks nonzero terminator sentinels, each output capacity's written prefix and split-surrogate canaries, and callback read order/visible offsets including the `INT32_MAX` boundary. Production decoding code is unchanged from the previously reviewed implementation. I ran `python3 tools/check_conventions.py --base upstream/main --head HEAD` and `git diff --check upstream/main...HEAD`; both pass. The author reports the ICU library rebuild and focused Linux test passing. Earlier exact-head reviews independently compared the decoder with pinned ICU 78.1 and ran Linux and Windows test builds. Console-version equivalence remains the documented limitation.
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!10961
No description provided.