feat(libSceLibreSsl3): implement ASN1_get_object #17068
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17068"
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 fishingpvalues on 2026-11-08T09:22:44Z.
What
Implements
ASN1_get_object(mXrusLhI3CI), whichlibSceLibreSsl3exported only as an import-resolution stub, following LibreSSL 4.0.0asn1_lib.c:0x80too-long flag and queuesASN1_R_TOO_LONGwhen the declared length exceeds the remaining input;0x80withASN1_R_HEADER_TOO_LONGqueued and the input cursor unchanged for a malformed header, a truncated high tag or length, an indefinite primitive and a length aboveLONG_MAX;*ppunchanged on every error path.A null output pointer or a negative input length throws where LibreSSL would dereference or read out of bounds. The PS5 ABI and console behaviour are unverified.
src/Asn1ObjectHeader.cppholds the export,tests/Asn1ObjectHeader.cppis registered asguest_libressl3_asn1_object_header, and the stub leavesAdditionalExports.cppwhile the declaration gains its real signature ininclude/Api.hpp.docs/dev/debt/libSceLibreSsl3.mdloses the row (125 to 124 callable exports, 116 to 115 named) and gains one Functional entry.Open PR #14465 is an alternate independent implementation of the same export; it is currently conflicting with
main.Tested
Linux x86-64 (CachyOS, GCC 16.2.1), Release,
BUILD_TESTING=ON, basemain828e44310e:guest_libressl3_asn1_object_headercovers universal, application and private classes, constructed and indefinite forms, high tags, long lengths with leading zero bytes, the too-long flag, truncated headers and lengths, indefinite primitive rejection, high-tag overflow, the error queue codes and the null and negative-argument throws.ctest --test-dir build -R '^guest_libressl3_asn1_object_header$' --output-on-failure: 1/1 passed.python3 tools/check_conventions.py --base origin/main: passed;tools/check_test_registration.py build: passed.Checklist
main; #14465 is an alternate implementation of the same export, not a dependencyNotImplemented_nid_no_patch).mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T12:57:30Z.
Review: COMMENTED
Windows run of head
44d5b8fc33, merged ontomain57c0f6a48d. GitHub shows this branch as conflicting, and the local merge stops indocs/dev/debt/libSceLibreSsl3.md, so for the run I tookmain's version of that file.Setup: Windows 11, WinLibs GCC 15.2 (
x86_64-ucrt-posix-seh), Release,BUILD_TESTING=ON.longis 32 bits on the Windows host. The export is declared and implemented with hostlong:long* plength,long omax,sizeof(long)andLONG_MAX. The guest'slongis 64 bits. On Linux and macOS the two agree, but MinGW is LLP64, solongthere is 4 bytes, and then:*plengthare written;omaxis read as 32 bits;count > sizeof(long)rejects a length of 5 to 8 bytes that LP64 LibreSSL accepts;LONG_MAXcaps lengths at 2^31 - 1.guest_libressl3_asn1_object_headerpasses here, as in the earlier Windows run, because the test uses hostlongon both sides.To check it the way a guest calls it, I added a local, unpushed differential test. The oracle is
ASN1_get_objectandasn1_get_lengthcopied from3rdparty/libressl-openbsd/src/lib/libcrypto/asn1/asn1_lib.c, withlongwritten asstd::int64_tandunsigned longasstd::uint64_t. The export was called with a pointer to an 8-byte length set to0x5A5A5A5A5A5A5A5A. Over 200,000 random headers of 1 to 20 bytes:0x5A5A5A5A00000049.04 85 01 00 00 00 00(length 2^32) returns0x80from both, but LP64 LibreSSL advances*ppand stores 4294967296 with the too-long flag. This PR takes the header-error path and leaves the length unwritten.The fix is the one
include/Api.hppalready uses ford2i_ASN1_INTEGER_nid_postfix(..., std::int64_t length):std::int64_t* plengthandstd::int64_t omaxin the declaration and the definition;std::uint64_tfor the accumulator;8andINT64_MAXin place ofsizeof(long)andLONG_MAX.A test row with a 5-byte length, and one that reads the length through an 8-byte slot, would catch this on Windows.
#14465, the other implementation of this export, is still open and also conflicts with
main.Pull request closed