feat(libSceLibreSsl3): implement OBJ_cmp #10631

Merged
MarcZX10 merged 8 commits from upstream-pr/10631 into main 2026-11-05 18:22:36 +00:00
MarcZX10 commented 2026-10-24 13:43:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:43:47Z.


What

Implements OBJ_cmp in libSceLibreSsl3 following the public LibreSSL source: objects are compared by encoded length first (the difference is returned) and then byte by byte, returning the difference of the first differing unsigned bytes. The 40-byte LP64 ASN1_OBJECT layout is the one used by #10461. Null objects, null data with a nonzero length and negative lengths throw. LibreSSL subtracts unequal lengths before reading data, so unequal negative lengths do not necessarily fault; only equal negative lengths reach its byte comparison. PS5 behavior and the module's LibreSSL version are not verified; the debt entry says so, including that the magnitude of a byte mismatch is the byte difference rather than whatever the console's memcmp returns.

Commits: implementation, test, debt entry.

Tested

Linux x86-64, GCC, full CMake build (Ninja, Release). guest_libressl3_obj_cmp covers equal encodings, the first differing byte in both directions, the length difference taking precedence, bytes above 0x7f compared as unsigned, empty encodings that must not read data, and the three rejected inputs. The host CPU (Xeon E5-1620 v2) fails the startup CPU-feature gate, so I ran the test with that check disabled in a local, uncommitted edit; it exits 0. tools/check_conventions.py and git diff --check pass. After review, I added negative-length mismatch and INT_MIN regressions and compiled the exact production source plus focused test with GCC C++20 -Wall -Wextra -Wpedantic -fsanitize=undefined -fno-sanitize-recover=undefined; the test passes. The prior implementation triggered UBSan signed overflow for INT_MIN versus length 1. No title or GPU involved. Open PRs #9970, #10452, #10461, #10490, #10491, #10493 and #10557 touch shared CMake/debt insertion points. This PR will land after #10493 and #10557 and rebase to retain their source-list and debt entries; #10493 carries the preceding LibreSSL dependency chain. #10461 is the source of the 40-byte ASN1_OBJECT layout used here. I am coordinating the order with #10493’s author; #10557 is also mine and will be rebased after #10493.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #10493 and #10557 (the shared source-list/debt edits are ordered first; this PR will rebase after both)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4995894662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10631). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T13:43:47Z. --- ### What Implements `OBJ_cmp` in libSceLibreSsl3 following the public [LibreSSL source](https://github.com/libressl/openbsd/blob/bc9483725c5815efb64b6d9acc52fc5fba139212/src/lib/libcrypto/objects/obj_lib.c): objects are compared by encoded length first (the difference is returned) and then byte by byte, returning the difference of the first differing unsigned bytes. The 40-byte LP64 `ASN1_OBJECT` layout is the one used by #10461. Null objects, null data with a nonzero length and negative lengths throw. LibreSSL subtracts unequal lengths before reading data, so unequal negative lengths do not necessarily fault; only equal negative lengths reach its byte comparison. PS5 behavior and the module's LibreSSL version are not verified; the debt entry says so, including that the magnitude of a byte mismatch is the byte difference rather than whatever the console's `memcmp` returns. Commits: implementation, test, debt entry. ### Tested Linux x86-64, GCC, full CMake build (Ninja, Release). `guest_libressl3_obj_cmp` covers equal encodings, the first differing byte in both directions, the length difference taking precedence, bytes above 0x7f compared as unsigned, empty encodings that must not read data, and the three rejected inputs. The host CPU (Xeon E5-1620 v2) fails the startup CPU-feature gate, so I ran the test with that check disabled in a local, uncommitted edit; it exits 0. `tools/check_conventions.py` and `git diff --check` pass. After review, I added negative-length mismatch and `INT_MIN` regressions and compiled the exact production source plus focused test with GCC C++20 `-Wall -Wextra -Wpedantic -fsanitize=undefined -fno-sanitize-recover=undefined`; the test passes. The prior implementation triggered UBSan signed overflow for `INT_MIN` versus length 1. No title or GPU involved. Open PRs #9970, #10452, #10461, #10490, #10491, #10493 and #10557 touch shared CMake/debt insertion points. This PR will land after #10493 and #10557 and rebase to retain their source-list and debt entries; #10493 carries the preceding LibreSSL dependency chain. #10461 is the source of the 40-byte `ASN1_OBJECT` layout used here. I am coordinating the order with #10493’s author; #10557 is also mine and will be rebased after #10493. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #10493 and #10557 (the shared source-list/debt edits are ordered first; this PR will rebase after both) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 15:34:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T15:34:10Z.

Review: COMMENTED


Checked against main b607bfdc8b and LibreSSL 4.0.0 (libressl-v4.0.0 tag, objects/obj_lib.c and asn1/asn1_local.h):

  • The comparison matches OBJ_cmp at 4.0.0 (obj_lib.c:125-134): length difference first, 0 for empty encodings without reading data, then unsigned bytes. The 40-byte layout and the offsets in the static_assert match struct asn1_object_st in asn1_local.h:74-80. (Discussion #8981 places libSceLibreSsl3 at LibreSSL 4.0.0, if you want to cite a version in the debt entry.)
  • Small citation fix: at bc9483725c (and at 4.0.0), OBJ_cmp is defined in objects/obj_lib.c, not obj_dat.c, so the link in the debt entry and the description points to the wrong file.
  • The debt wording "negative lengths throw where LibreSSL faults" is a bit broad. LibreSSL returns a->length - b->length before reading data, so for lengths -1 and 0 it returns -1 rather than faulting; only equal negative lengths reach memcmp. Throwing for any negative length seems fine to me (and throws(&negative, &empty) pins it), but could the sentence say exactly that?
  • The branch merges cleanly into current main on its own (3-way git merge-tree, no conflicts), and main still has the OBJ_cmp stub (Export.cpp:223), so there's no duplication.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638800220 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10631#pullrequestreview-5638800220). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T15:34:10Z. **Review:** COMMENTED --- Checked against main b607bfdc8b and LibreSSL 4.0.0 (`libressl-v4.0.0` tag, objects/obj_lib.c and asn1/asn1_local.h): - The comparison matches `OBJ_cmp` at 4.0.0 (obj_lib.c:125-134): length difference first, 0 for empty encodings without reading `data`, then unsigned bytes. The 40-byte layout and the offsets in the static_assert match `struct asn1_object_st` in asn1_local.h:74-80. (Discussion #8981 places libSceLibreSsl3 at LibreSSL 4.0.0, if you want to cite a version in the debt entry.) - Small citation fix: at bc9483725c (and at 4.0.0), `OBJ_cmp` is defined in `objects/obj_lib.c`, not `obj_dat.c`, so the link in the debt entry and the description points to the wrong file. - The debt wording "negative lengths throw where LibreSSL faults" is a bit broad. LibreSSL returns `a->length - b->length` before reading data, so for lengths -1 and 0 it returns -1 rather than faulting; only equal negative lengths reach `memcmp`. Throwing for any negative length seems fine to me (and `throws(&negative, &empty)` pins it), but could the sentence say exactly that? - The branch merges cleanly into current main on its own (3-way `git merge-tree`, no conflicts), and main still has the `OBJ_cmp` stub (Export.cpp:223), so there's no duplication. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
MarcZX10 commented 2026-11-02 04:57:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:57:47Z.

Review: COMMENTED


Reviewed — include request met, one reported failure unverified

The ObjCmp.cpp include request is met at this head, and the only open point is a test failure reported on an older head.

What I ran

Live head 79d5bea103f9255b457ed835314d26209fe4895a (matches batch). gh pr view for statusCheckRollup; gh api reads of comments; git show <head>:<path> on ObjCmp.cpp and Api.hpp; git log on ObjCmp.cpp. Nothing was built or run.

Results

Check Result Note
eligibility SUCCESS hosted
conventions SUCCESS hosted
labels SUCCESS hosted
report SUCCESS hosted
windows SUCCESS hosted; the Windows run of guest_libressl3_obj_cmp is not in this result
linux, relinker, relinker-asan, register-context, write-watch SKIPPED hosted skips

Findings

  • ObjCmp include (28 Oct): met. ObjCmp.cpp:6 includes prx/libSceLibreSsl3/include/Api.hpp, and Api.hpp:51 declares OBJ_cmp_nid_postfix. The include came in commit 79d5bea103 by Dean Galvin (oneandonlydean), a fix-up pushed to this branch.
  • Reported failure (babyhuey, 27 Oct): the report was run on head 13f4b3d7e43, not this head. It says guest_raise_exception failed on the reporter's machine and also fails on main 0a570f617d8. I did not run it. I cannot confirm the failure or the main comparison.

Sources

Not verified

  • The guest_raise_exception failure and its comparison with main.
  • The 1404 of 1413 count from the reporter's run, which was on an older head.
  • A Windows run of guest_libressl3_obj_cmp on this head.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732250957 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10631#pullrequestreview-5732250957). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T04:57:47Z. **Review:** COMMENTED --- # Reviewed — include request met, one reported failure unverified The `ObjCmp.cpp` include request is met at this head, and the only open point is a test failure reported on an older head. ## What I ran Live head `79d5bea103f9255b457ed835314d26209fe4895a` (matches batch). `gh pr view` for `statusCheckRollup`; `gh api` reads of comments; `git show <head>:<path>` on `ObjCmp.cpp` and `Api.hpp`; `git log` on `ObjCmp.cpp`. Nothing was built or run. ## Results | Check | Result | Note | |---|---|---| | eligibility | SUCCESS | hosted | | conventions | SUCCESS | hosted | | labels | SUCCESS | hosted | | report | SUCCESS | hosted | | windows | SUCCESS | hosted; the Windows run of `guest_libressl3_obj_cmp` is not in this result | | linux, relinker, relinker-asan, register-context, write-watch | SKIPPED | hosted skips | ## Findings - ObjCmp include (28 Oct): met. `ObjCmp.cpp:6` includes `prx/libSceLibreSsl3/include/Api.hpp`, and `Api.hpp:51` declares `OBJ_cmp_nid_postfix`. The include came in commit `79d5bea103` by Dean Galvin (`oneandonlydean`), a fix-up pushed to this branch. - Reported failure (babyhuey, 27 Oct): the report was run on head `13f4b3d7e43`, not this head. It says `guest_raise_exception` failed on the reporter's machine and also fails on `main` `0a570f617d8`. I did not run it. I cannot confirm the failure or the main comparison. ## Sources - https://github.com/boykopovar/AnyPS5/blob/79d5bea103f9255b457ed835314d26209fe4895a/core/libs/prx/libSceLibreSsl3/src/ObjCmp.cpp#L6 - https://github.com/boykopovar/AnyPS5/blob/79d5bea103f9255b457ed835314d26209fe4895a/core/libs/prx/libSceLibreSsl3/include/Api.hpp#L51 ## Not verified - The `guest_raise_exception` failure and its comparison with `main`. - The 1404 of 1413 count from the reporter's run, which was on an older head. - A Windows run of `guest_libressl3_obj_cmp` on this head.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10631
No description provided.