feat(libSceNpCommon): implement sceNpUtilXmlEscape and sceNpUtilXmlUnescape #12818
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12818"
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-29T11:11:22Z.
What
Implements
sceNpUtilXmlEscapeandsceNpUtilXmlUnescapein place of theirNotImplementedstubs. Both take(char* dst, size_t dstSize, const char* src, size_t srcLength, size_t* required). The signature and behaviour are read fromlibSceNpCommon.sprxof firmware 13.60 (disassembly, not measured on a console).Both
0x80550601for a nullsrc, a zerosrcLength, or neitherdstnorrequired.dstnull, they only measure. Otherwise they write a terminator, and*requiredgets the length including it.0x80550602whendstis too small, checked before each piece is written and again for the terminator. Bytes written before that point stay written.sceNpUtilXmlEscape"&'<>become"&'<>, and other printable ASCII, tab, LF and CR are copied.0x80550608.Strings.cpp's existingUtf8SequenceLength,IsValidSequenceandIsAllowedTextByte, which already encode those rules for the JSON helpers.sceNpUtilXmlUnescape&and every other byte, NUL included, are copied.Bounds, as in the module: neither function bounds an entity or a UTF-8 sequence by
srcLength. A sequence whose lead byte is inside the source is copied whole, and an entity whose&is inside it is matched whole, reading the bytes after the source. The tests pin this ("&"with length 1 gives&).The debt file replaces the two "signature unknown" entries with one entry stating the source and the unmeasured points.
Tested
Linux (CachyOS, GCC, Release):
ctest --test-dir build -R 'public_headers|np_common' --output-on-failure, 70/70 passed.TestXmlTextinGuestNpCommonRuntime.cppcovers the entities both ways, measuring, UTF-8 and whitespace pass-through, each refused byte class, the buffer edges, the argument errors and the reads pastsrcLength.Comparison against the firmware code: I relinked the 13.60 module with this repo's relinker and ran both functions under unicorn (x86-64 emulation on a PC, not a console). Neither calls an import.
dstandrequired.dstplus 16 bytes pastdstSize(prefilled 0xCC), and*required.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)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 rooklz on 2026-10-29T11:50:59Z.
Review: COMMENTED
Reviewed on macOS arm64 (Apple clang, ASan + UBSan,
-fno-sanitize-recover=all) at4b94c6905c, as a standalone build oflibSceNpCommon/Strings.cppandTestXmlText. I didn't run the full CMake lane.Result:
TestXmlTextpasses with no sanitizer reports.git merge-treeagainst mainba5b5330b3is clean,check_conventions --headpasses, andpr_overlapprobed 1403 open PRs and found no overlap (7 share files, all merge cleanly). The provenance is the module's code (firmware 13.60 disassembly), whichREVERSE_ENGINEERING.mdlists as a source, and the debt entry says it wasn't measured on a console. The implementation is written from the contract rather than mirroring a disassembly.Mutants (16 single-edit changes to Strings.cpp). The existing test kills 6. Some of the behaviour the body describes isn't pinned:
>=), still passes. So does "bytes written before the error stay written".length + 2, still passes.srcLengthin unescape still passes. The existing"&"/1 row only covers the&-is-last case, where both versions copy&.The rows below kill all 10 non-equivalent survivors. The last 2 mutants I tried turned out to be equivalent. Head is green and every row is red on its mutant:
(These go after the last
sceNpUtilXmlUnescapeargument row. Each one is a claim from your body or the debt entry, so if your unicorn corpus disagrees with any of them, the corpus wins.)Nits
AI-assisted review.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T12:34:31Z.
Review: APPROVED
Re-reviewed at
01a22cc28bon macOS arm64 (Apple clang, ASan + UBSan,-fno-sanitize-recover=all). I used the same standalone build as before:Strings.cppplusTestXmlTextand its helpers, taken verbatim from the PR.TestXmlTextpasses.>=, partial write undone, unescape per-character check dropped /length + 2, entity bounded bysrcLength, 0xF5–0xF7 leads refused, 3-byte surrogates refused.requiredwritten on the terminator failure is killed by the newlength == 99row. Writing it on the per-piece failure path still survives, because that row only reaches the terminator check. This is minor. If you want it pinned,length = 99; sceNpUtilXmlEscape(escaped, 1, "ab", 2, &length)→0x80550602,length == 99would cover it, provided your differential agrees.check_conventions --head,git diff --checkandgit merge-treeagainst main5454cd2e45are all clean.Approving.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:54:04Z.
Review: COMMENTED
Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (
Unblocks: noneis allowed), and it contained no code review.