feat(libSceLibreSsl): report ASN1_STRING_to_UTF8 errors through the ASN.1 error queue #11050
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11050"
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 harisibrar1 on 2026-10-25T15:21:40Z.
What
ASN1_STRING_to_UTF8throws on malformed input and on allocation failure. The debt entry says so: "Malformed encodings and allocation failure throw until ASN.1 error-queue reporting is implemented". Main now has that error queue (LibreSslPutError_nid_no_patchinsrc/Error.cpp, read byERR_get_error), so this reports those cases the way LibreSSL 2.5.4 does. Discussion #8981 places 2.5.4 on firmware 13.40.In 2.5.4,
ASN1_STRING_to_UTF8(a_strex.c:624-646) callsASN1_mbstring_copywith a stackASN1_STRINGand only writes*outon success.ASN1_mbstring_ncopy(a_mbstr.c:95-256) then does the following, each failure beingASN1error(reason)(ERR_PUT_error(13, 0xfff, reason)) and -1:INVALID_BMPSTRING_LENGTH(129). UniversalString with a length that isn't a multiple of 4:INVALID_UNIVERSALSTRING_LENGTH(133). Both are checked before the data is read.UTF8_getcrejects (bad lead or continuation byte, overlong form, surrogate, above U+10FFFF, truncated):INVALID_UTF8STRING(134).traverse_string):ILLEGAL_CHARACTERS(124).ERR_R_MALLOC_FAILURE(65). For a UTF8String the copy goes throughASN1_STRING_set, which reports it too, so it's queued twice.ASN1_STRING_to_UTF8now returns -1 and queues those codes throughLibreSslPutError_nid_no_patch, leaving the output untouched. The cases where 2.5.4 has undefined behaviour still throw, now asstd::invalid_argument/std::length_errorlikeDigest.cpp's guards:intintoverflow of the converted sizeThe conversion runs in two passes, as @thepoppfish suggested in review: the first decodes the whole string, reporting any malformed character, and counts the UTF-8 size; then the one guest allocation is made and the second pass writes into it. No host buffer is allocated, so no
std::bad_alloccan reach the guest.A null output now throws only once a conversion has succeeded, since 2.5.4 dereferences it only there; a malformed string with a null output returns -1 like the source. The export no longer reaches
NotImplemented_nid_no_patch. The debt sentence is rewritten to match.Tested
Windows 11, WinLibs GCC 15.2.0 r7, full Release build on main
3a2c51afd2with this change: no failed steps.tests/Asn1.cppgainsMalformedStrings, which checks the return value, the untouched output and the exact queued code for each case:guest_libressl*tests pass, 3 runs on the two-pass head, includingguest_libressl_asn1andguest_libressl_asn1_allocator.Asn1.cpp, both ASN.1 tests abort with "ASN1_STRING_to_UTF8_nid_postfix not implemented" (2 runs).tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.pylists only open PRs that conflict with main on the debt file; none touchesAsn1.cpp.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:26:59Z.
Review: DISMISSED
The new error-queue handling covers failure of
malloc_nid_postfix, but conversion also allocates throughstd::vector<unsigned char> converted:AppendCharactercallspush_backonce to four times per character, and vector growth can throwstd::bad_allocbefore the guest allocator is reached. That exception currently escapes this exported C ABI function instead of returning -1 and queuingERR_R_MALLOC_FAILURE, so allocation failure is not fully handled as the PR body and debt entry claim. The pinned LibreSSL 2.5.4 path reports destination-allocation failures throughASN1error(ERR_R_MALLOC_FAILURE)inASN1_mbstring_ncopy(including bothASN1_STRING_type_newand the output buffer allocation):github.com/libressl/openbsd@2e2c612066/src/lib/libcrypto/asn1/a_mbstr.c (L1426-L1451). Please either map failures from the intermediate conversion storage into the documented ASN.1 error/return behavior, or avoid that allocating intermediate, and add focused coverage for that failure path. I could not run the product test locally: full CMake configuration stops because the SDL2 submodule is uninitialized and XRandR development support is unavailable.git diff --checkpassed; conventions completed with a debt-length warning.Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-26T00:20:02Z.
Review: APPROVED
Re-reviewed exact head §
d2bb979ffc§. The two-pass implementation resolves the host-scratch-allocation issue from Marc's review and my supporting reproduction. It adopts the approach I suggested; I am not claiming the production file is byte-identical to the earlier scratch patch.Fresh independent native Windows / GCC 16.2.0-6 UCRT, C++20, §-O1 -g -fno-inline -fno-lto§, static C++ runtime:
acb900c194§ also passes 8/8, 0 skipped, 0.31 s, including the same 18 error/allocation cases and 1352 Unicode cases. Local merge §a6f1174dfb8e8831aa1b8c045dd5255bbfe7a6c6§, tree §ce237dc03a6cee583c075080d800ef4dceebf96b§. The complete conversion/error/test source blobs are unchanged by this merge.Non-blocking documentation cleanup: the resolved return/error-code list can be removed from the debt paragraph. The remaining gap and existing source provenance fit in this shorter replacement:
Scope: these executables compile the complete production
Asn1.cppandError.cppwith real headers/error queue. The explicit heap-registration/malloc test adapter from my earlier replay supplies and counts the guest allocation boundary; this is not the full libc/LibreSSL product build. I did not rerun the author's broader ten-test product suite, hosted CI, Linux/macOS, a console/title, or a canonical overlap scan. The original head's negative controls remain historical evidence for that commit. AI-assisted review/replay: Codex.