feat(libScePfs): implement query, command, and validation exports #14096
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14096"
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 akkadbakkad89 on 2026-10-31T18:39:49Z.
What
Implements seven
libScePfsexports —scePfsGetHeaderReadCommand,scePfsGetBlockTableReadCommand,scePfsGetSingleBlockReadCommand,scePfsGetPreadBlockRange,scePfsGetUncompressedSize,scePfsGetWorkBufferSize,scePfsValidate— from the bundled decryptedlibScePfs.prxshipped with Stellar Blade (PPSA13197), whose disassembly pins every behaviour below.0x43534650, version u16 at+4, uncompressed total at+0x18; errors0x8a780001–0x8a780005.+0x28== 2): u64 boundary table at+0x30, 48-bit masked entries.+0x48, types 3 (block table) and 7 (data region) keyed on the low byte; block-table entries are pairs masked 44 bits.scePfsGetWorkBufferSizereturns the constant0xed0d8(allocator helper0x15b0caseedi=8gives0xa8 + 0x6d020,0x15a0adds0x10, export adds0x80000).scePfsValidatemodes 0/1/2: mode 2 additionally walks the block boundaries checking<= 0x40000spans (v3) /< 0x20001deltas and<= total(v2).scePfsGetSingleBlockReadCommandwith a missing type-3 index record andblockIndex >= 0dereferences null on console; the host returns0x8a780003like the missing type-7 case.scePfsPreadandscePfsPreadDecompressBlockstill throwNotImplemented_nid_no_patch: the former's block-read worker loop and the latter's internal range decoder (0xf0a20, calls0x6380,0xaa0) are not yet ported; both gaps are documented indocs/dev/debt/libScePfs.md.Tested
New
guest_pfstest (Windows, MinGW): read-command layouts for v2/v3, block-range arithmetic incl. the firmwarefound != offsetcorrection quirk, single-block commands, validation levels and all error paths — passes.tools/check_conventions.py --base origin/mainclean;tools/pr_overlap.py --branchreports no overlap with open PRs. Not run against a title.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T18:43:57Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The new
scePfsGetPreadBlockRangeaccepts an out-of-range request when its 64-bit end calculation wraps, then can return wrapped block indices or walk beyond the v3 table.What I ran
Reviewed exact head
43714ccd26770439af397db3f04212548bdda909against PR baseca073ec3ad0d766ea9f4658e418a5c977001a353. The no-build precheck recorded a clean individual merge preview against the current baseca073ec3ad0d766ea9f4658e418a5c977001a353. Environment: Linux x86-64, Python 3.11.2, Git 2.39.5. No C++ build or test was run.Results
guest_pfs_teststarget andadd_test(NAME guest_pfs ...)in the changed CMake file appear to register it, so this signal is a false positive on inspection.Precheck output
The overall precheck status reflects the unavailable local helper scripts, not a failed repository convention check.
Findings
Blocking
At
Export.cpplines 93 and 119,offset + size > totalis evaluated after unsigned 64-bit addition. Fortotal = UINT64_MAX,offset = UINT64_MAX - 1, andsize = 2, the sum wraps to zero, so both v2 and v3 pass the range guard even though the requested end exceedstotal. The v2 path can then returnUINT32_MAXas a block index; the v3 path uses the huge offset to indexblockTable.The round-up expression also adds
0x3ffffto the end before shifting, which can overflow for otherwise in-range values nearUINT64_MAX. Please use subtraction-based bounds (offset <= totalandsize <= total - offset), overflow-safe ceiling division for block indices, and reject indices that cannot be represented by theuint32_toutputs. Add v2 and v3 regression cases aroundUINT64_MAXthat assert an error without reading beyond the supplied table.Non-blocking
None.
Sources
Not verified
I did not build or run
guest_pfs_tests; hosted Windows was still running, and Linux/specialized jobs were skipped. I did not validate behavior against a PS5 or a game image.To get this to a good state
Add overflow-safe range and rounding checks with regression cases for v2 and v3, then I will rerun the same no-build checks and re-review the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T20:27:43Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
The update fixes the wrapping range arithmetic, but the v2 path still accepts a zero-length request whose first block index exceeds the
uint32_toutput range and silently wraps it.What I ran
Reviewed head
5ab9369ddfba3ae8669e83cc5553617b067f067fagainst PR baseca073ec3ad0d766ea9f4658e418a5c977001a353; the merge preview against currentmain0836dfdf4fecb1e0326100c490476e15d3a74da5was clean. Environment: Debian Linux, Python 3.11.2, GCC 12.2.0. No local C++ build or CTest run.Results
GuestPfs.cppis included through${LIBS_INCLUDE_DIR}/tests/GuestPfs.cppand registered asguest_pfsin the changed CMake fileadd_testare presentUnedited local command output
The ABI audit returned
"status": "passed"and"findings": []. The test-quality warning waspossible-unregistered-cpp-test; manual inspection confirmed the registration described above.Negative control
No local negative-control run was performed because exercising this C++ test requires a build. The hosted Windows job passed on the reviewed head; it is not a mutation test.
Findings
Blocking
In the v2 branch,
firstBlockOutis cast fromoffset >> 0x12, but onlylastIndexis checked againstUINT32_MAX(reviewed source). Fortotal = offset = 0x4000000000000andsize = 0, the request passes the bounds check;firstIndexis0x100000000,lastIndexis0xffffffff, and the cast returnsfirstBlockOut == 0. The function therefore reports a wrapped first block instead of rejecting an index that cannot fit its output. This contradicts the new overflow hardening and the debt note's claim that unrepresentable block indices return0x8a780005.Please check
offset >> 0x12againstUINT32_MAXbefore assigning the output, and add a v2 zero-length boundary regression that expectsOutOfRange.Non-blocking
The update appropriately removes tests that asserted still-unimplemented exports throw. The PR now documents its older-firmware differences and the remaining malformed-v3 validation-count divergence.
Sources
Not verified
I did not run the C++ test locally or verify behavior against a PS5. The hosted Linux and specialized jobs were skipped; only the hosted Windows job is evidence of a compiled test run on this head.
To get this to a good state
Reject the oversized v2 first index and add the zero-length boundary regression. I will rerun the same no-build checks and review the exact new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T07:57:48Z.
Review: COMMENTED
Re-checked — new head, no blocking findings
The new head
255caee65ab8befea3d10638d8b1c09e8db48a66adds the first-index range check that blocked the previous head, and the hosted Windows job passedguest_pfson this exact head.What I ran
Exact head reviewed:
255caee65ab8befea3d10638d8b1c09e8db48a66, one commit (fix(libScePfs): reject v2 ranges whose first block index cannot fit) on top of5ab9369ddfba3ae8669e83cc5553617b067f067f, the head that received my earlier CHANGES_REQUESTED review. PR baseca073ec3ad0d766ea9f4658e418a5c977001a353. Merge preview against currentmainc674f8c14da93df7a6b37657117ca3f58357477f: clean (git merge-tree --write-treeexit 0, no conflicts).Environment: Debian host, git 2.39.5, system Python 3. No build, no compile, no local C++ test run. The checks were run from the trusted checkout
/marc/AnyPS5/toolsagainst the PR's git objects; the PR's own tools and tests were not executed.The
pr_precheck.pywrapper was not run for this head, because its isolated checkout would execute PR-head tooling and tests, and its helpers are absent from detached checkouts. The component checks above were run by hand instead.Results
git diff --checkover the PR rangepr_abi_audit.py, by hand)passed, 9 symbols, 0 findings; lexical only, not an ABI proofpr_test_quality.py)possible-unregistered-cpp-testfinding, a false positive:core/libs/prx/libScePfs/CMakeLists.txtregistersguest_pfs_testsfrom${LIBS_INCLUDE_DIR}/tests/GuestPfs.cppas testguest_pfsBuildrun 41245988671, job 124670344335guest_pfspassedUnedited command and log output
Negative control
scePfsGetPreadBlockRange(0, 0x4000000000000) == OutOfRange(GuestPfs.cppL170)5ab9369d, which lacks thefirstIndex > 0xffffffffcheck (Export.cppL126-L133 at that commit)0x100000000to0and returns 0.Findings
Blocking: none. The blocking item from the previous head is fixed. The v2 path now checks
firstIndextogether withlastIndexbefore theuint32_tassignments, and the v3 path already checked both indices before its table scan. The regression cases cover the unrepresentable zero-length index and the representable boundary.Non-blocking: none.
Sources
Not verified
guest_pfs; the only run evidence is the hosted Windows job at this exact head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-10T18:28:49Z.
Review: APPROVED
Reviewed — looks good
The reviewed head has no remaining blocking findings, and the changed guest test step completed successfully on the exact head.
What I ran
I previously reviewed all five changed files at head
255caee65ab8befea3d10638d8b1c09e8db48a66against PR baseca073ec3ad0d766ea9f4658e418a5c977001a353, including the exact-head no-build precheck and export audit. In this follow-up, I rechecked the overflow guard and its regressions, current PR state, CI run, and current-main merge preview. The merge preview against currentmain865323b2a9e7f7f056c313cf23a71eb8fecd0882is clean.Environment: Linux x86-64; Git 2.39.5. I did not compile locally.
Results
865323b2a9e7.guest_pfsrunHosted results
The Windows Build run was triggered for head
255caee65ab8befea3d10638d8b1c09e8db48a66and completed successfully. Its job includes the successful “Build and run changed guest core/libs tests” step. Separately, the reviewer comment #6720266778 reportsguest_pfspassing 3 of 3 runs on Windows 11 with WinLibs GCC 15.2.The conventions, labels, report, eligibility, and library-portability checks passed. Linux, relinker, ASan, register-context, and write-watch jobs were skipped.
Negative control
No negative-control or mutation run was performed.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
Linux and specialized jobs were skipped; no local build or CTest run, console run, or title-level behavior check was performed. The Windows 11 3/3 report is supplied by another reviewer and was not independently reproduced.
To get this to a good state
No further code change is requested for this head. If the PR receives a new commit, I will review and test that exact head.