fix(libSceNpCommon): store the high hex digit before checking the low one in sceNpStrParseHex #12913
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12913"
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 hypermoist on 2026-10-29T14:12:15Z.
What
Fixes
sceNpStrParseHexandsceNpStrnParseHexfor input with a bad low digit. InlibSceNpCommon.sprxof firmware 13.60 (read from disassembly, not measured on a console), both functions store each byte in two steps:high << 4;(high << 4) | low.So when the high digit is valid and the low digit is refused, the call returns
0x80558009and leaves that byte ashigh << 4. AnyPS5 checked both digits before writing, so it left that byte unchanged. Example:"0A5G"gives0A 50on the firmware, but0Aand the old byte on main.The fix keeps the shared
ParseHexhelper and only reorders the store. Everything else is unchanged: the odd-length check, the capacity check (0x80558008), and the accepted characters (0-9a-fA-F).Tested
Linux (CachyOS, GCC 16.2, Release):
ctest --test-dir build -R 'np_common|public_headers' --output-on-failure, 70/70 passed.TestHexAndCopiesgets two rows:Comparison against the firmware code: I relinked the 13.60 module with this repo's relinker and ran the functions under unicorn (x86-64 emulation on a PC, not a console).
length / 2;sceNpStrBuildHex, unchanged here, as a regression check on its vectorised path.The generator and harness are
np_hex_make_cases.py/np_hex_replay.cppin https://gist.github.com/hypermoist/1834cf221fd737cdb4cca272cc1156d1. The gist has no module or recorded output.emucall.pythere now also emulates the AVX2 byte instructions thatsceNpStrBuildHexuses. It also zeroes the upper half of a register after a VEX.128 instruction that unicorn runs natively. With that change, the earlier corpora in the gist regenerate byte for byte.Windows not built. Not run on a console.
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)pr_overlapreports no overlap with open pull requests)Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T14:14:18Z.
Review: APPROVED
Reviewed — looks good
The high-nibble partial write matches the reported firmware sequence, and an exact-head focused harness confirmed the new result-buffer behavior.
What I ran
Reviewed head
67bab6bdfee157a31d73b198b9aa2478c1ceae77againstmainatbb04a4f1ea0175e9e4f149f0359a764d62ff3296; the merge preview is clean (treed15042efbd108e0eee3905a0ac9c37fc8b9029bd). Environment: Linux 6.1.0-54-amd64, GCC 12.2.0.I compiled the changed
Strings.cppwith a small harness that checks both the low-digit partial write and the high-digit no-write case:Results
Unedited output
Negative control
"0AG5"with the second output byte initialized to0xFF.0x80558009and left the byte at0xFF.Findings
Blocking
None found in the reviewed diff.
Non-blocking
The author reports a 13.60 firmware disassembly comparison and a 9,000-case Unicorn differential run in the PR description; I did not independently reproduce that corpus or run on a console. Full CTest and Windows were not run locally.
Sources
ParseHeximplementationNot verified
The full
np_commonCTest target, the author's 9,000-case differential harness, other operating systems, and PS5 console behavior were not independently verified here.