fix(libSceLibreSsl3): return d2i_ASN1_INTEGER errors instead of throwing #14171
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14171"
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 danielhorngt on 2026-10-31T21:59:04Z.
What
d2i_ASN1_INTEGERin libSceLibreSsl3 threw on every rejected encoding and on allocation failure. It now returns NULL with the error queue, old output and input pointer the module leaves.The behaviour follows the firmware 13.42 measurements already linked from the debt entry, taken by running the decrypted module natively on a PC, not on a console. The parsing order follows LibreSSL 4.0.0
asn1_check_tag,asn1_d2i_primitive_contentandc2i_ASN1_INTEGER_cbs.*out0x0DFFF0A8,0x0DFFF03A0x0DFFF066,0x0DFFF03A0x0DFFF09B,0x0DFFF03A0x0DFFF0E70x0DFFF03E0x0DFFF041twice*indoes not move on a NULL return. A nonnegative length with a null input still throws, because the module faults there.The old object is now freed before the empty and redundant-sign checks, not after them, as the measurements show. Errors go on libSceLibreSsl's queue through
LibreSslPutError_nid_no_patch.One path has no measurement: content over
INT_MAXbytes follows LibreSSL, whereasn1_c2irefuses it beforec2i_ASN1_INTEGER_cbsruns (NULL, nothing queued, nothing allocated,*outuntouched). The debt entry records this and is cut to what is still open.guest_libressl3_asn1_testsnow also linkslibSceLibreSsl, to read the queue.Tested
Windows 11, WinLibs GCC 15.2.0, Release, on this branch. No title or homebrew was run, and I found no title that hits these paths.
ctest -R 'libressl|guest_crypto_memcmp|^public_headers': 102 of 102 passed on the first commit. After theINT_MAXfix,ctest -R 'guest_libressl3_|guest_crypto_memcmp|^public_headers': 73 of 73 pass, includingguest_libressl3_asn1.0x0DFFF041once, checking constructed before the length, and checkingINT_MAXafter freeing the old object.guest_libressl3_asn1failed for all five.check_conventions.py --base upstream/mainpasses.Not run: the full test suite, Linux, macOS, or any comparison with a console.
pr_overlap.pyexited non-zero because six PRs could not be compared automatically: #9970, #10461, #10557, #10631, #10960 and #12928. They shareCMakeLists.txtor the debt file. I compared them by hand and none edits the ASN.1 test link line or the ASN.1 integer debt entry. No open PR changesIntegerDecoder.cpportests/Asn1.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 CodingBreadd on 2026-10-31T22:16:51Z.
Review: DISMISSED
Reviewed — changes requested
The decoder matches LibreSSL 4.0.0 and the 13.42 measurements on every tested path. The one untested path, content over
INT_MAXbytes, does not do what the PR body and debt entry say: it frees the caller's old object, but LibreSSL leaves it alone.What I ran
Reviewed head
302eb1fb4c81b46a57396645cf1f3c834dafe6c3against basef776fddcffd1cfece220ecdd894371988b164f6a. That base is also currentmain, and the merge preview was clean. Environment: Windows 11 x86-64, Python 3.14.7. I did not build or run CTest locally.I also read the pinned LibreSSL
ce488b78e0bdsources (asn1/tasn_dec.c,asn1/asn1_lib.c,asn1/a_int.c,asn1/a_string.c) side by side withIntegerDecoder.cpp.Results
ReadIdentifier/ReadLength/ReadIntegermatchasn1_get_identifier_cbs,asn1_get_length_cbsandasn1_check_tag: same order (identifier → tag/class → length → primitive-indefinite →TOO_LONG), same overflow guards, same0x7freserved rejection.NESTED_ASN1_ERRORis pushed only for header failures, asasn1_d2i_primitivedoes.TYPE_NOT_PRIMITIVE-after-length order, the free-before-empty-check order, theasn1_aint_keep_twos_paddingrule (FF 00…kept) and the redundant-sign rejection all matchasn1_d2i_primitive_contentandc2i_ASN1_INTEGER_cbs. TwoMALLOC_FAILUREs matchASN1_STRING_type_newplusasn1_item_ex_new.FreeIntegermatchesASN1_STRING_free/ASN1_STRING_clear, including theASN1_STRING_FLAG_NDEF(0x10) handling.RejectionsandAllocationFailurescover every row of the PR table, with and without an old object.302eb1fb4c81built and passedguest_libressl3_asn1, with 2539/2539 passing. Linux and the specialized jobs were skipped;labelswas still pending at the snapshot.Unedited local output
git diff --checkproduced no output and exited 0.Findings
Blocking
Content over
INT_MAXbytes frees the caller's old object; LibreSSL leaves it untouched. In LibreSSL 4.0.0,asn1_d2i_primitive_contentcallsasn1_c2i. That function returns 0 whenCBS_len(content) > INT_MAX, beforec2i_ASN1_INTEGER_cbsruns. So for that input the old*outis not freed,*outis not set to NULL, nothing is allocated and nothing is queued. Thedata_len > INT_MAXcheck insidec2i_ASN1_INTEGER_cbs(a_int.c#L187) is a second check thatd2inever reaches. At this head the check sits onIntegerDecoder.cpp:167, afterFreeInteger(*output); *output = nullptr;(line 143) and after a full-sizemallocandmemcpy(line 164). Given a 2³¹-byte integer and an old object, the export frees the caller's object and nulls*out, while LibreSSL returns NULL and leaves both alone.The PR body says this path "follows LibreSSL (old output freed, NULL, nothing queued)", and the debt entry says it follows LibreSSL 4.0.0, so the code and both documents disagree with the pinned source. Real inputs almost never reach this path, but the documented contract is wrong, and the fix also removes a needless 2 GiB copy. Reject before touching the output, and drop the later check:
Then correct the PR body's sentence. After this change the path never reads the content bytes, so a test can reach it: reserve a little over 2 GiB without committing it (
VirtualAlloc(MEM_RESERVE)/mmap(PROT_NONE)), commit only the first page, write a02 84 80 00 00 00header and pass a matching length. If you would rather not add that test, keep the "not tested" wording in the debt entry.Non-blocking
None found.