fix(libSceNpCommon): avoid hexadecimal capacity overflow #12772
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12772"
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 StoneDC on 2026-10-29T08:40:50Z.
What
Prevents unsigned overflow in sceNpStrBuildHex capacity validation. The old length * 2 expression can wrap and admit an undersized output; the new size == 0 / (size - 1) / 2 guard checks the same intended capacity condition before dereferencing input or writing output.
Implementation basis and limits: the existing capacity-first rule and NP_ERROR_BUFFER_TOO_SMALL in libSceNpCommon/Strings.cpp, plus the mathematical requirement 2*length+1 <= size. This retains the current error code rather than inventing firmware error priority. Ordinary sizes, case selection, NUL termination and no-write-on-short-output behavior are covered. PS5 behavior for impossible lengths was not measured.
Integration review: the exact topic head was checked with the repository overlap tool against main
edf6804cf52c62eacafc592dd6142cb4efe5bd05. No overlapping open PR was reported. All 20 topic commits also merged independently into current validation main4c7d275bef89d309313d16bc2bc05d37a1b50be2; their combined integration2a0489dd307a9c98b9b353ea7282b65809db07ddwas built and tested. Depends on: none; no other candidate branch is required to build or exercise this change.Tested
The same new fixture against the exact old production Strings.cpp triggered AddressSanitizer stack-buffer-overflow; the changed production source passed ASan+UBSan. Full-configuration Linux and Windows builds ran guest_np_hex_capacity against the actual library, including huge lengths and ordinary capacity boundaries; no skips.
Topic head:
a0ee7cda10450c6b091a9806a4d999dbc6b5b7da, based onf88c86bf6cdd2c74bcdb31e45ba877d4993e62e5. Local platforms: Ubuntu/WSL GCC 15.2, CMake 4.2.3, Python 3.14.4; Windows MinGW GCC 15.2, CMake 4.3.1, Python 3.14.3. Applicable conventions, whitespace, script registration and current-main three-way merge checks passed. Linux full-product builds and subsequent focused library rebuilds were performed; Windows used the full configuration and the affected library/test targets. The combined 11 system-library CTests passed on both platforms. No game or PS5 measurement is claimed; macOS and hosted full-build CI are not reported as passed.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)Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T01:42:36Z.
Review: APPROVED
Windows 11, WinLibs GCC 15.2.0 r7, Release. Head
a0ee7cda10merged into upstream/main93dbd0f82a:guest_np_hex_capacitypasses.Strings.cppsegfaults (Exception: SegFault). That's the wrappedlength * 2admitting the huge lengths and writing past the 16-byte buffer, the same overflow you saw under ASan.size == 0 || length > (size - 1) / 2is exactlysize < 2 * length + 1without the multiplication, so the ordinary boundaries are unchanged. The capacity loop checks that.