Skip to content

feat(libSceLibreSsl): implement X509_STORE_add_cert - #13285

Closed
JaceTheBlu wants to merge 43 commits into
boykopovar:mainfrom
JaceTheBlu:feat/libressl-store-add-cert
Closed

JaceTheBlu wants to merge 43 commits into
boykopovar:mainfrom
JaceTheBlu:feat/libressl-store-add-cert

Conversation

@JaceTheBlu

@JaceTheBlu JaceTheBlu commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements X509_STORE_add_cert in libSceLibreSsl, on top of the X509 from #13266. This is stacked on #13266, and through it #11359 and #11129. Merge those first; this PR's own diff is then only the store change, its tests and its debt entry.

It follows LibreSSL 2.5.4 x509_lu.c:

  • It allocates a 16-byte X509_OBJECT and gives the certificate one more reference.
  • It looks up the subject in the object cache with sk_find. That lookup sorts the cache first, through the store's comparator: by type, then by canonical subject length, then by its bytes. So each new certificate is pushed after the sorted ones, and the next add sorts again.
  • A failed object allocation or push puts ERR_R_MALLOC_FAILURE from ERR_LIB_X509 on the queue. A failed push also drops the reference and frees the object.
  • A null certificate returns 0 with no error.

The comparator that X509_STORE_new installs no longer throws for certificates. X509_STORE_free now frees stored certificates with X509_free, as sk_X509_OBJECT_pop_free does.

There is a new entry in docs/dev/debt/libSceLibreSsl.md, and the pending count goes from 286 to 285.

Adding a certificate whose subject is already in the store throws, including adding the same certificate twice. LibreSSL then calls X509_cmp, which needs:

  • X509_check_purpose's SHA-1 hash and extension cache;
  • a DER encoder.

These cases also throw:

  • a subject marked modified, which LibreSSL re-encodes;
  • a stored CRL;
  • a null store or certificate info.

When it throws, the add first drops the reference it took and frees its object, so the certificate and the store are left as they were. The X509_STORE entry no longer says that stored certificates throw.

Tested

Debian container, GCC 14.2, full Release build of head ed7a8e090a: ctest -R 'libressl|crypto_memcmp' passes 38 of 38. tools/check_test_registration.py and python3 tools/check_conventions.py --base upstream/main pass.

  • guest_libressl_x509_store checks:

    • references;
    • the exact cache order after each add, including stack growth and an empty subject;
    • a certificate shared by two stores;
    • comparator results by type;
    • the throws listed above, with the reference counts and the cache unchanged after each one.
  • guest_libressl_x509_store_allocator checks three failures:

    • The object allocation fails.
    • The push's reallocation fails.
    • An add throws, which must free its object.

    It checks the error code, the reference count and what is freed, and that a later add succeeds.

  • guest_libressl_oracle (ANYPS5_LIBRESSL_ORACLE) now also fills a store on each side with 1 to 14 random certificates with distinct subjects, plus some null ones. After each add, it compares:

    • the return value and error queue;
    • the stack's count, allocation and sorted flag;
    • the order of the cached certificates;
    • every reference count, before and after X509_STORE_free.

    The 3,000 cases show no difference. The 6 AES_set_*_key cases are the existing ones described in the debt file.

Not tested on Windows, on a title or on a console.

Checklist

🤖 Generated with Claude Code

JaceTheBlu and others added 13 commits October 25, 2026 22:56
…_ASN1_OBJECT

i2t_ASN1_OBJECT threw and was declared without parameters. It now
prints an object's long name, or its short name, or its dotted OID, as
OBJ_obj2txt does in LibreSSL 2.5.4, the version string the module
holds: the NID is the object's own or found by the same binary search
over the same order, an unassigned NID reports OBJ_R_UNKNOWN_NID for
each name lookup, a truncated subidentifier returns 0 after the parts
already written, and arcs past 64 bits are printed exactly.

The 956 objects (short and long names, NID, OID) and their search order
are generated from 2.5.4's objects.txt and obj_mac.num with its own
objects.pl and obj_dat.pl, so d2i code can later hand out the same
static objects LibreSSL does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…blocks

On Linux the first exception the allocation test throws goes through
libc's unwinder, which caches two frame descriptions with operator new
for the rest of the process. The test counted them as blocks leaked by
i2t_ASN1_OBJECT and failed every fault case. A first failing conversion
now runs before the counted cases, and the blocks it leaves are not
tracked. Against the head before the allocation fix the test still
reports the escaped exceptions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The export threw and was declared without parameters. It follows
LibreSSL 2.5.4's x509_obj.c: each entry is written as /SN=value with
the short name from the object table, or the dotted OID when the NID
is unknown, bytes outside ' ' to '~' escaped as \xHH and the zero
filler of a four-byte GeneralString dropped. A caller buffer keeps the
entries that fit; without one the text grows in a guest-heap BUF_MEM
as buffer.c and recallocarray do, and a failed allocation returns null
after the BUF and X509 malloc errors. d2i_X509 needs it for the cached
subject line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	core/libs/prx/libSceLibreSsl/Export.cpp
#	core/libs/prx/libSceLibreSsl/include/Api.hpp
#	core/libs/prx/libSceLibreSsl/src/X509Name.cpp
#	docs/dev/debt/libSceLibreSsl.md
# Conflicts:
#	core/libs/prx/libSceLibreSsl/CMakeLists.txt
#	core/libs/prx/libSceLibreSsl/include/Api.hpp
#	docs/dev/debt/libSceLibreSsl.md
# Conflicts:
#	core/libs/prx/libSceLibreSsl/CMakeLists.txt
#	docs/dev/debt/libSceLibreSsl.md
# Conflicts:
#	docs/dev/debt/libSceLibreSsl.md
# Conflicts:
#	core/libs/prx/libSceLibreSsl/CMakeLists.txt
#	docs/dev/debt/libSceLibreSsl.md
# Conflicts:
#	core/libs/prx/libSceLibreSsl/CMakeLists.txt
#	core/libs/prx/libSceLibreSsl/Export.cpp
#	core/libs/prx/libSceLibreSsl/include/Api.hpp
#	docs/dev/debt/libSceLibreSsl.md
Port the LibreSSL 2.5.4 template decoder for the items an X509 holds
(certificate, X509_CINF, algorithms, names with their canonical
encoding, validity, public key, extensions and ASN1_TYPE), with the
X509 layouts of x509.h, the x509 reference count and cached subject,
and the error codes LibreSSL queues. guest_libressl_oracle compares
generated and mutated certificates with LibreSSL 2.5.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port X509_STORE_add_cert from LibreSSL 2.5.4 x509_lu.c: the 16-byte
X509_OBJECT, the extra certificate reference, the subject lookup that
sorts the object cache by canonical subject before each push, and the
malloc failure errors. X509_STORE_free now frees stored certificates.

Adding a certificate whose subject is already in the store throws, as
LibreSSL then compares the two with X509_cmp, which needs the SHA-1
hash and extension cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

The duplicate-certificate and modified-subject error paths leak the candidate object and its added certificate reference, and the PR description does not use the required template.

What I ran

Reviewed head 25592c3e2a6db62703e28744073b56a03c784f33 against PR base 8e68a7d7b9f6aeedb0ca03eee115571640555988; the dependency checker confirmed #13266's current head is included in this PR. Its merge-preview result became stale while main advanced, so I do not rely on it. Environment: Debian 12 x86-64, Python 3.11.2, Git 2.39.5. No C++ build or tests were run locally.

git diff --check 8e68a7d7b9f6aeedb0ca03eee115571640555988...25592c3e2a6db62703e28744073b56a03c784f33
python3 tools/check_conventions.py --base 8e68a7d7b9f6aeedb0ca03eee115571640555988 --head 25592c3e2a6db62703e28744073b56a03c784f33 --title 'feat(libSceLibreSsl): implement X509_STORE_add_cert' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13285-25592c3e2a6d/pr-body.md
python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base 8e68a7d7b9f6aeedb0ca03eee115571640555988 --head 25592c3e2a6db62703e28744073b56a03c784f33 --json
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13285
python3 tools/pr_stack_check.py 13285 --repo boykopovar/AnyPS5 --output-dir /tmp/stack-13285

Results

Check Result
Diff whitespace Passed; git diff --check produced no output.
Conventions and PR template Failed: the required ### What, ### Tested, and ### Checklist headings are absent.
ABI audit passed_with_warnings; its two lexical findings are private helpers (CompareObjects, LoadFile), not exported functions. This is not a complete ABI or compile check.
Dependency/mergeability #13266's exact head is included. The current-main preview became stale because main advanced during the check; no conclusion is drawn from that preview.
Focused and oracle tests The author reports 38/38 `libressl
Hosted CI Intake, conventions, labels, eligibility, and progress report were queued at final refresh.
Unedited check output excerpts
(pull request): error: [pr-template] Fill in the pull request template: add the '### What' heading of the template
(pull request): error: [pr-template] Fill in the pull request template: add the '### Tested' heading of the template
(pull request): error: [pr-template] Fill in the pull request template: add the '### Checklist' heading of the template
3 findings, 3 errors; GitHub shows at most 10 error annotations, the job summary lists all
{
  "status": "passed_with_warnings",
  "findings": [
    {
      "symbol": "CompareObjects",
      "kind": "public-declaration-not-found",
      "message": "No APS5_VABI declaration was found in a header; verify whether this is intentionally private or missing from the public interface."
    },
    {
      "symbol": "LoadFile",
      "kind": "public-declaration-not-found",
      "message": "No APS5_VABI declaration was found in a header; verify whether this is intentionally private or missing from the public interface."
    }
  ]
}

Findings

Blocking

  1. X509_STORE_add_cert_nid_postfix increments certificate->references and allocates object before Find. For duplicate subjects and modified subjects, Find throws through the documented unsupported paths; that bypasses both the decrement and free_nid_postfix(object). Each such call leaks the object and leaves the certificate reference count elevated. Clean up the candidate object and undo the reference increment on every exceptional exit (for example, use scoped ownership), then extend SameSubject to assert unchanged references after each thrown call.
  2. The PR description omits the repository-required template headings and checklist. Please preserve and fill in the template sections, including ### What, ### Tested, and ### Checklist with the declared dependencies. The repository's conventions check currently fails on these omissions.

Non-blocking

The implementation and test changes are extensive; I reviewed the store insertion path and the new duplicate/modified-subject cases that expose the resource leak. The author-reported test and oracle results have not been independently reproduced here.

Sources

Not verified

I did not build or run C++ tests or the LibreSSL oracle. Hosted CI was pending. The precheck's merge preview was stale after main advanced; ABI-audit warnings are lexical and need no public-export conclusion. I did not run the test-quality helper because it is absent from the isolated precheck checkout.

To get this to a good state

Please make the insertion path exception-safe, assert the reference counts remain unchanged after the expected throws, and update the description using the repository template. I will rerun the same diff, conventions, ABI, and dependency checks on the new head; build-dependent tests remain outside this initial no-build review.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 11146 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 11176 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 11466 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15278 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15279 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 15280 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 16529 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 17844 core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 18460 core/libs/prx/libSceLibreSsl/CMakeLists.txt
docs/dev/debt/libSceLibreSsl.md
PR 19044 core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 23078 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 23088 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 23139 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 23336 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 23573 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
core/libs/prx/libSceLibreSsl/src/X509.cpp
core/libs/prx/libSceLibreSsl/tests/Oracle.cpp
core/libs/prx/libSceLibreSsl/tests/OracleReference.cpp
core/libs/prx/libSceLibreSsl/tests/X509.cpp
docs/dev/debt/libSceLibreSsl.md
PR 24322 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 24401 core/libs/prx/libSceLibreSsl/Export.cpp
PR 24415 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 24582 core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 24612 core/libs/prx/libSceLibreSsl/include/Api.hpp
PR 24910 core/libs/prx/libSceLibreSsl/CMakeLists.txt
PR 24917 core/libs/prx/libSceLibreSsl/CMakeLists.txt

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Progress report (85f73c1 → 0ecf9da)

📈 System libraries: 42.89% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libSceLibreSsl X509_free_nid_postfix
libSceLibreSsl d2i_X509_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl 309/473 (65.33%) 311/473 (65.75%) +0.42%

…t throws

The duplicate-subject and modified-subject paths threw after taking a
certificate reference and allocating the object. Drop the reference and
free the object before rethrowing, and check the counts in the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maskym

maskym commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Windows result for head 25592c3e2a, merged into main 42d009f5f3 (the PR's Tested section names no Windows run).

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. Build clean.

The tree also carried the open PR #13286, merged cleanly, so the run is a joint one. The tests this PR adds or extends all pass: guest_libressl_x509_store, _x509_store_allocator, _x509, _x509_allocator, _x509_name, _x509_name_oneline and _x509_name_oneline_allocator, as does the whole ^guest_libressl|^guest_kernel_sys set: 61/61, three runs. guest_libressl_oracle, which this PR also touches, is built only with ANYPS5_LIBRESSL_ORACLE=ON and was not run here. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@JaceTheBlu JaceTheBlu closed this Oct 30, 2026
@JaceTheBlu JaceTheBlu reopened this Oct 30, 2026
@JaceTheBlu

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Thanks. Both points are addressed on ed7a8e090a.

  • The leak. X509_STORE_add_cert now drops the reference it took and frees its object before rethrowing, whether the lookup throws or the push does.
    • SameSubject now checks the reference counts and the cache size after each expected throw.
    • The allocator test checks that a throwing add allocates and frees exactly one object.
  • The template. The description now has ### What, ### Tested and ### Checklist. check_conventions.py with this title and body passes locally.

I reran on this head:

  • ctest -R 'libressl|crypto_memcmp': 38 of 38 pass.
  • The LibreSSL 2.5.4 oracle: 3,000 store cases, no difference.

(Sorry for the close/reopen just before this; that was a misclick.)

JaceTheBlu and others added 3 commits October 31, 2026 00:10
…ports

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
….cpp ports

Also drop the executable bit that four files of this branch gained.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 16, 2026
JaceTheBlu and others added 2 commits November 16, 2026 09:42
Compare decoded certificates with the reference only when the host long is 8 bytes. On an LLP64 host the reference library lays X509 out with 4-byte longs, so the oracle compared two different layouts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The store comparison reads reference certificates through the LP64 layout too, so it runs only when the host long is 8 bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 16, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The inspected implementation at head f27b826502d2ab01205e20a2603e9371e7285d40 has no verified blocking defect; the description reports passing tests, but I did not run them.

What I ran

No commands or tests were run. I inspected the prepared diff and targeted source through repo_read.py.

Results

Check Result Note
Prepared diff inspection passed Reviewed relevant store changes
Tests not run Results in the description are author reported

Findings

Blocking

None verified in the inspected code.

Non-blocking

None.

Not verified

The full review is incomplete: I did not read all changed files, so an approval is not justified. The manifest indicates changes across multiple files; I inspected the description, commits, the start of the diff, and targeted ranges in X509Store.cpp. files.json was not available at the review path; exclusions and the complete set of reviewed files are not verified. Tests, Windows, title, and console behavior were not verified.

To get this to a good state

Nothing is required.

main reverted the wcstombs change that made guest_multibyte_locale fail on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feat(libSceLibreSsl): implement X509_STORE_add_cert — no blocking findings

Nothing blocks this; the points below are optional. The review is partial (see Not verified), so this is a comment, not an approval.

What I ran

  • Read description.md, commits.md, manifest.json and the first 995 lines of diff.patch (CMake, Export.cpp, include/Api.hpp, the start of src/X509.cpp).
  • Read diff.patch lines 2030–2075 (d2i_X509, X509_free, CertInfo) and 2076–2355 (src/X509Store.cpp: comparator, Sort/Find, FreeObject, X509_STORE_free, X509_STORE_add_cert).
  • repo_read.py search for uses of the renamed enc field and for the X509_free and d2i_X509 definitions. Both searches returned 0 matching lines, so they checked nothing.
  • No build and no test run. The description reports ctest -R 'libressl|crypto_memcmp' at 38/38 on head 41809f501b; I did not reproduce it.

Results

Check Result Note
Build and ctest Not run Description reports a pass; not reproduced here.
Logic read: X509_STORE_add_cert Read src/X509Store.cpp:2322–2350 (diff). Reference is taken before the lookup and dropped on every failure path. Null certificate returns 0 with no error.
Logic read: comparator and Find Read src/X509Store.cpp:2231–2294 (diff). Duplicate subjects throw, as the description says.
Store free Read src/X509Store.cpp:2305–2315 (diff). Stored certificates are released with X509_free.
d2i_X509 / X509_free Read in part src/X509.cpp:2059–2071 (diff). The body of the decoder was not read.
Rename of LibreSslX509CertInfo::enc to encoding Not checked Search returned no matches; callers not verified.
Test files Not read tests/X509.cpp, tests/X509Store.cpp, tests/Oracle.cpp, tests/OracleReference.cpp.
Debt entry Not read docs/dev/debt/libSceLibreSsl.md, hunks at lines 128, 157 and 173. The "286 to 285" count is not verified.

Findings

Blocking

None found in the code I read.

Non-blocking

None recorded. I did not find a concrete defect in the sections I read.

Not verified

  • Build, ctest, and the 3,000-case oracle run. None were run here.
  • src/X509.cpp from diff line 995 to the end of the new file (about 1,900 lines in total) and the decoder body in src/X509.cpp around the d2i_X509 call.
  • The enc to encoding rename in include/Api.hpp and all its callers in the library. The reader search returned no matches, so this was not checked.
  • The static_assert offsets in src/X509.cpp for the new 176-byte LibreSslX509 layout. They were not checked against the header.
  • The four test files and the debt entry (listed above).
  • files.json was not read, so I cannot say which files it lists as reviewed.

To get this to a good state

Nothing is required.

@ycbuzi

ycbuzi commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Tested 41809f501b merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 3 tests failed out of 6106; 99% tests passed, 4 tests failed out of 6106. 3 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 6106; 100% tests passed, 0 tests failed out of 6106. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Retested head 41809f501b on Windows (the head moved since my earlier run), merged alone into main 56c87adbdc.

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. Microsoft Defender on this machine quarantines 34 AGC test executables as Trojan:Win64/ShellCode.MKA!MTB when they are linked (the case docs/dev/BUILD.md describes), so their objcopy step fails on both trees and those tests do not run here. This PR adds no other build failure.

The tests this PR adds or extends, guest_libressl_x509_der, guest_libressl_x509_der_allocator, guest_libressl_x509_store, guest_libressl_x509_store_allocator, pass 4/4, three runs. guest_libressl_oracle is behind -DANYPS5_LIBRESSL_ORACLE=ON, off by default; I did not build or run it. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 18, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: reject oversized DER lengths before narrowing them to int.

What I ran

Reviewed head 0ecf9daf7de09ff04cdd0a826f559eeda44c78bc using the prepared diff and repo_read.py source reader. No tests or build commands were run. The description reports a Debian/GCC 14.2 test run; that result was not independently run here.

Results

Check Result Note
Source review failed Oversized DER length can be narrowed
Tests/build not run Author reports passing tests

Findings

Blocking

  • core/libs/prx/libSceLibreSsl/src/X509.cpp:1247: PrimitiveDecode narrows the decoded content length from int64_t to int without checking that it fits. A valid encoded length above INT_MAX can wrap or truncate, causing ContentToValue to process a length different from the encoded content length and potentially read past the input buffer. Reject values above INT_MAX before this cast (and preserve the matching error behavior).

Non-blocking

None.

Not verified

  • The reported test suite and build were not run during this review.
  • Windows, title, and console behavior were not tested, as the author also notes.
  • Read all changed files listed in the manifest: core/libs/prx/libSceLibreSsl/CMakeLists.txt, core/libs/prx/libSceLibreSsl/Export.cpp, core/libs/prx/libSceLibreSsl/include/Api.hpp, core/libs/prx/libSceLibreSsl/src/X509.cpp, core/libs/prx/libSceLibreSsl/src/X509Store.cpp, core/libs/prx/libSceLibreSsl/tests/Oracle.cpp, core/libs/prx/libSceLibreSsl/tests/OracleReference.cpp, core/libs/prx/libSceLibreSsl/tests/X509.cpp, core/libs/prx/libSceLibreSsl/tests/X509Store.cpp, and docs/dev/debt/libSceLibreSsl.md. No files were excluded by the prepared manifest.

To get this to a good state

Reject DER content lengths that cannot be represented by int before casting, add coverage for that boundary, and rerun the reported build and test checks on the updated head.

@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Retested head 0ecf9daf7d on Windows (the head moved since my earlier run), merged alone into main 7b2370120c.

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so the tree was built with ninja -k 0. This PR adds no other build failure.

The tests this PR adds or extends, guest_libressl_x509_der, guest_libressl_x509_der_allocator, guest_libressl_x509_store, guest_libressl_x509_store_allocator, pass 4/4, three runs. guest_libressl_oracle is behind -DANYPS5_LIBRESSL_ORACLE=ON, off by default; I did not build or run it. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

@JaceTheBlu

Copy link
Copy Markdown
Contributor Author

Closing this one: #23574 put an X509_STORE_add_cert on main on Nov 19, with its own object comparison and duplicate check in src/X509Store.cpp. Updating this branch would mean replacing that implementation, so it no longer makes sense as a separate PR.

The rest of the stack (#13266, #13546, #13547, #13877) does not depend on this PR and stays open, up to date with main.

Thanks @maskym and @MarcZX10 for testing and reviewing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants