Skip to content

fix(libSceIme): keep complete UTF-8 and stray continuation bytes at the 64 KiB clipboard cap - #23295

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
gurtgg:fix-ime-clipboard-utf8-bound-continuation
Nov 25, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
gurtgg:fix-ime-clipboard-utf8-bound-continuation

Conversation

@gurtgg

@gurtgg gurtgg commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

What

  • Fix ImeHostText::BoundedUtf8Size (core/libs/prx/libSceIme/include/ImeHostText.hpp) so that when size > MaxClipboardBytes (65536) and text[MaxClipboardBytes] is a UTF-8 continuation byte ((b & 0xc0) == 0x80), it scans back at most 3 bytes from MaxClipboardBytes - 1 across continuation bytes, inspects the lead byte using DecodeUtf8Lenient's exact lead ranges (2, 3, 4, or 0), and backs up to pos only when pos + sequenceBytes > MaxClipboardBytes.
  • Previously, BoundedUtf8Size walked backward unconditionally over every continuation byte, discarding complete 2-, 3-, or 4-byte UTF-8 characters ending at index 65535 when followed by a stray 0x80..0xbf byte, and dropping up to the entire 64 KiB clipboard on runs of non-UTF-8 continuation bytes instead of replacing each invalid byte with U+FFFD.
  • High-reach PRX input method library (sceImeOpen host clipboard paste path; imported by PPSA19639, PPSA24191, PPSA03001, PPSA07426, PPSA29866).

Tested

  • Extended bounds_huge_clipboards (core/libs/prx/libSceIme/tests/HostText.cpp) with negative-control assertions for a 65540-byte 0x80 run, complete 2-/3-/4-byte UTF-8 characters ending at index 65535 followed by a stray 0x80 at index 65536, and valid 2-/3-/4-byte sequences straddling index 65536.

Checklist

  • tools/check_conventions.py passes (UTF-8 no-BOM LF, zero disallowed comments, Conventional Commits)
  • Negative-control regression test fails against unmodified main and passes after fix
  • AI-assisted: yes
  • Depends on: none

@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 1d332fafe9:

  • Conventions: tools/check_conventions.py passed.
  • Build: ime_host_text_tests built cleanly.
  • CTest (ime_host_text):
    1/1 Test #3897: ime_host_text ....................   Passed    0.08 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIme/include/ImeHostText.hpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3897: ime_host_text ....................***Failed    0.03 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified ImeHostText::BoundedUtf8Size boundary condition when size <= MaxClipboardBytes (returns size immediately)
    • Verified BoundedUtf8Size when text[MaxClipboardBytes] is an ASCII byte or lead byte ((b & 0xc0) != 0x80) (returns MaxClipboardBytes)
    • Verified backwards scan limit (MaxClipboardBytes - pos < 3) bounds search to at most 3 continuation bytes, correctly locating any 2-, 3-, or 4-byte UTF-8 lead byte
    • Verified sequence length matching logic against UTF-8 lead byte ranges (2 for 0xc2..0xdf, 3 for 0xe0..0xef, 4 for 0xf0..0xf4) and verified sequence straddle check (pos + sequenceBytes > MaxClipboardBytes ? pos : MaxClipboardBytes)
    • Verified interaction between BoundedUtf8Size and DecodeUtf8Lenient, confirming complete characters ending at MaxClipboardBytes are preserved while stray continuation bytes are bounded cleanly to MaxClipboardBytes without truncation cascades
    • Verified test coverage in HostText.cpp covers both stray continuation byte runs and all combinations of 2-, 3-, and 4-byte sequences terminating at or straddling the 64 KiB boundary

Looks Good To Me

@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Windows result for head 1d332fafe9, merged alone into main 866864a5bc (the PR's Tested section names no Windows run).

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. This PR adds no other build failure.

ime_host_text, the test this PR adds or extends, passes 3 of 3 runs. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@github-actions github-actions Bot added the prx label Nov 18, 2026
@gurtgg gurtgg closed this Nov 19, 2026
@gurtgg gurtgg reopened this Nov 19, 2026
This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 1d332fafe9, applied with git apply on main fd4aeed483 together with the other 26 PRs of one batch (#24498, #24665, #17297, #21499, #21726, #22534, #12900, #17843, #22051, #22075, #23087, #23206, #23222, #23227, #13147, #17482, #21935, #17477, #18272, #22858, #22929, #23028, #23916, #24179, #24706, #12619). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
ime_host_text (1 test, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6525 tests) on the RTX 3080 has 8 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Traced to other PRs of the batch, each by reverting it and testing again: #18272 (guest_audio_out), #12900 (guest_user_service_initial_user_bounds); none is in this PR's area. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): guest_content_search. The 2125 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@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 changed UTF-8 boundary logic preserves complete sequences and bounds clipboard decoding at 64 KiB on head 1d332fafe95dcd8450b4b222126ecb471a1f9fb8; the changed files were fully reviewed, and no checks were run.

What I ran

Read the prepared description, commits, manifest, diff, both changed files, and the clipboard caller using repo_read.py. No tests or other commands were run; the author reports a conventions check and negative-control test, which I did not independently run.

Results

Check Result Note
Changed-file review passed Both changed files read in full
Tests and conventions check not run Reported by author only

Findings

Blocking

None.

Non-blocking

None.

Not verified

No test or conventions command was run. No files were excluded: both files in manifest.json were included and read in full. The author-reported checks were not independently verified.

To get this to a good state

Nothing is required.

@oneandonlydean
oneandonlydean merged commit 77f57b9 into boykopovar:main Nov 25, 2026
28 of 29 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.

6 participants