fix(libSceConvertKeycode): look up keyboard types without signed overflow #10968
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10968"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:32:20Z.
What
ImeKeyboardType::LookUp(core/libs/prx/libSceConvertKeycode/ImeKeyboardType.hpp), used bysceConvertKeycodeGetImeKeyboardType, computedkeyboardType - kFirstMappedType(16) instd::int32_t. For a keyboard type belowINT32_MIN + 16, such as the0x80000000the existingguest_convert_keycodecase passes, that subtraction overflows, which is undefined behavior. UBSan reports it:The index is now computed in 64 bits. Every keyboard type maps to the same IME keyboard type as before, and types outside the table still map to 0.
Two commits: fix, test. The test adds
static_assert(ImeKeyboardType::LookUp(INT32_MIN, 0, 0) == 0)and the same forINT32_MAX;LookUpisconstexpr, and signed overflow is an error in a constant expression, so with the previous code the test file does not compile (overflow in constant expression). This makes the regression visible without a sanitizer.Tested
Linux x86-64 (Debian 12, GCC 12). In an
-DANYPS5_ENABLE_ASAN=ONbuild with-fsanitize=undefinedandUBSAN_OPTIONS=halt_on_error=1,guest_convert_keycodefails on currentmainwith the report above and passes with the fix, together with the sixguest_convert_keycode_title_*tests. Without the fix,guest_convert_keycode_testsstops compiling once the newstatic_assertlines are added; with it, it compiles.python3 tools/check_conventions.py --base upstream/main --head HEADandgit diff --check upstream/mainpass. Windows, macOS and hardware were not run.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)