Repository navigation
fix(libSceIme): keep complete UTF-8 and stray continuation bytes at the 64 KiB clipboard cap - #23295
Conversation
…he 64 KiB clipboard cap
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 1d332fafe9:
- Conventions:
tools/check_conventions.pypassed. - Build:
ime_host_text_testsbuilt 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.hppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #3897: ime_host_text ....................***Failed 0.03 sec 0% tests passed, 1 tests failed out of 1 - 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
|
Windows result for head Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release,
AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine. |
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
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.
What
ImeHostText::BoundedUtf8Size(core/libs/prx/libSceIme/include/ImeHostText.hpp) so that whensize > MaxClipboardBytes(65536) andtext[MaxClipboardBytes]is a UTF-8 continuation byte ((b & 0xc0) == 0x80), it scans back at most 3 bytes fromMaxClipboardBytes - 1across continuation bytes, inspects the lead byte usingDecodeUtf8Lenient's exact lead ranges (2,3,4, or0), and backs up toposonly whenpos + sequenceBytes > MaxClipboardBytes.BoundedUtf8Sizewalked backward unconditionally over every continuation byte, discarding complete 2-, 3-, or 4-byte UTF-8 characters ending at index 65535 when followed by a stray0x80..0xbfbyte, and dropping up to the entire 64 KiB clipboard on runs of non-UTF-8 continuation bytes instead of replacing each invalid byte withU+FFFD.sceImeOpenhost clipboard paste path; imported byPPSA19639,PPSA24191,PPSA03001,PPSA07426,PPSA29866).Tested
bounds_huge_clipboards(core/libs/prx/libSceIme/tests/HostText.cpp) with negative-control assertions for a 65540-byte0x80run, complete 2-/3-/4-byte UTF-8 characters ending at index 65535 followed by a stray0x80at index 65536, and valid 2-/3-/4-byte sequences straddling index 65536.Checklist
tools/check_conventions.pypasses (UTF-8 no-BOM LF, zero disallowed comments, Conventional Commits)mainand passes after fix