fix(libkernel): stop cutting regular-file reads and writes at 0x7ffff… #24076

Merged
jpirz merged 2 commits from upstream-pr/24076 into main 2026-11-20 22:36:27 +00:00
jpirz commented 2026-11-20 05:21:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jpirz on 2026-11-20T05:21:25Z.


What

On Linux one read, write, pread, pwrite, readv, writev, preadv or pwritev moves at most 0x7ffff000 bytes (read(2)), and on macOS read and write reject more than INT_MAX bytes. sceKernelRead, sceKernelWrite, sceKernelPread, sceKernelPwrite, the four vector exports, their POSIX forms and the AIO read and write commands handed each request on a host regular file to one such call, so on Linux any request above 0x7ffff000 bytes came back short although the file held the data. FreeBSD 11.4 accepts up to SSIZE_MAX per call for a 64-bit process (iosize_max_clamp = 0 in sys/kern/sys_generic.c), and POSIX allows a short regular-file read only at end of file or after a signal. The Windows vector path already loops.

File::TransferInParts (POSIX branch of Stdio.cpp, declared in File.hpp) sends a transfer of more than 0x7ffff000 bytes on a regular file to the host in parts of at most 1 GiB with readv/writev/preadv/pwritev, splitting the iovec array at part boundaries. It stops at a short part and returns the bytes already moved when a later part fails. It returns -2, like the shared-memory helpers, for transfers that one host call serves whole, totals above SSIZE_MAX, negative or overflowing offsets and descriptors that are not regular files; those keep their original single host call, so transfers up to 0x7ffff000 bytes stay atomic as before, and pipes, sockets, terminals and every existing error path are unchanged. Call sites: NativeRead/NativeWrite (Open.cpp), NativePread/NativePwrite and the four vector exports (Stdio.cpp), and the AIO NativePread/NativePwrite (Aio.cpp).

A new libkernel debt entry records that, for a split transfer, another transfer or seek on the same open file, or a write to the same file, can run between two parts (FreeBSD's vn_io_fault holds the file offset and a range lock for the whole transfer), and the paths that are still one host call: Windows read, write, pread, pwrite, their sceKernel forms and the AIO read and write commands (unchanged; they throw above UINT_MAX bytes, and _read rejects more than INT_MAX), positioned and AIO writes to an O_APPEND file on macOS (WritevAtEnd), and writes to shared memory objects. None of this was measured on a console.

Tested

Ubuntu 24.04 x86-64 container, rebased onto and built at d50640e264 (CMake, Ninja, Release, gcc 13, BUILD_TESTING=ON; targets chosen by tools/select_tests.py, plus libs).

  • New check LargeTransfers in guest_file_vector (not on Windows): one 64 MiB file mapped 34 times as a contiguous 0x88000000-byte buffer; a 0x84000000-byte sparse file is read with sceKernelRead, sceKernelPread, an AIO read command, sceKernelReadv and sceKernelPreadv, then 0x88000000 bytes are written with sceKernelWritev, checking counts, the file offset and size, and marks that straddle the 1 GiB part boundaries. The file is truncated to 0 right after the write.
  • Fail before (d50640e2 with the test, library sources reverted): File vector check failed at line 176 in 3 of 3 runs, with strace showing the host read of 0x88000000 bytes returning 0x7ffff000 (2147479552). Earlier, a separate program showed every read form (sceKernelRead, read, sceKernelPread, pread, sceKernelReadv, readv, sceKernelPreadv, preadv, AIO read) and every write form (sceKernelWrite, sceKernelPwrite, sceKernelWritev, sceKernelPwritev, AIO write) returning 0x7ffff000 for 0x88000000-byte requests.
  • Pass after: guest_file_vector passes in 4 of 4 runs, about 3 s each. In CI the write side is covered through sceKernelWritev only; the positioned and single-buffer write forms were checked with the separate program, not in the repository, to keep the test at one 2 GiB write.
  • Unchanged edge cases, base and fix compared before the rebase (at a445e0f0): a pipe read stays one call (1 MiB returned), a destination unmapped at 1.25 GiB returns 0x50000000, an unmapped first byte returns EFAULT, a negative AIO offset returns EINVAL, sceKernelRead of SIZE_MAX returns EFAULT and read of SIZE_MAX EINVAL.
  • Selected tests (tools/select_tests.py, 5540 of 6339, ctest -j3): 5319 pass, 193 are skipped (mostly agc_driver_*) and 28 fail, none because of this change: 24 socket tests that open IPv6 sockets, which this container lacks (guest_sce_net and guest_socket_listen_backlog_bounds among them, both failing with the library sources reverted too); agc_driver_image_gather_lod and agc_driver_image_table_packed_guards, which fail on this container's software Vulkan (llvmpipe) with the sources reverted too; and agc_driver_pm4_order_signal, a latency threshold that fails on and off on this loaded machine with and without the change, and agc_driver_runtime_buffer_spans_x3_spans, which timed out in the parallel run and passes alone.
  • Not compiled or run on macOS or Windows. No macOS-only line changed: the iovec whole declarations in NativePwrite and the AIO NativePwrite moved out of #ifdef __APPLE__ and are now compiled on Linux too; Windows code is untouched.
  • tools/pr_overlap.py --branch against the open pull requests: no conflicting lines or shared exports. Older pull requests that conflict with main share Open.cpp, Stdio.cpp, Aio.cpp, File.hpp or the libkernel debt file; read by hand, none of them splits large regular-file transfers (#12700 and #12965 split blocking pipe reads for cancellation).

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5408242514 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24076). Originally posted by [jpirz](https://github.com/jpirz) on 2026-11-20T05:21:25Z. --- ### What On Linux one `read`, `write`, `pread`, `pwrite`, `readv`, `writev`, `preadv` or `pwritev` moves at most `0x7ffff000` bytes ([read(2)](https://man7.org/linux/man-pages/man2/read.2.html)), and on macOS `read` and `write` reject more than `INT_MAX` bytes. `sceKernelRead`, `sceKernelWrite`, `sceKernelPread`, `sceKernelPwrite`, the four vector exports, their POSIX forms and the AIO read and write commands handed each request on a host regular file to one such call, so on Linux any request above `0x7ffff000` bytes came back short although the file held the data. FreeBSD 11.4 accepts up to `SSIZE_MAX` per call for a 64-bit process (`iosize_max_clamp = 0` in `sys/kern/sys_generic.c`), and POSIX allows a short regular-file read only at end of file or after a signal. The Windows vector path already loops. `File::TransferInParts` (POSIX branch of `Stdio.cpp`, declared in `File.hpp`) sends a transfer of more than `0x7ffff000` bytes on a regular file to the host in parts of at most 1 GiB with `readv`/`writev`/`preadv`/`pwritev`, splitting the iovec array at part boundaries. It stops at a short part and returns the bytes already moved when a later part fails. It returns -2, like the shared-memory helpers, for transfers that one host call serves whole, totals above `SSIZE_MAX`, negative or overflowing offsets and descriptors that are not regular files; those keep their original single host call, so transfers up to `0x7ffff000` bytes stay atomic as before, and pipes, sockets, terminals and every existing error path are unchanged. Call sites: `NativeRead`/`NativeWrite` (`Open.cpp`), `NativePread`/`NativePwrite` and the four vector exports (`Stdio.cpp`), and the AIO `NativePread`/`NativePwrite` (`Aio.cpp`). A new libkernel debt entry records that, for a split transfer, another transfer or seek on the same open file, or a write to the same file, can run between two parts (FreeBSD's `vn_io_fault` holds the file offset and a range lock for the whole transfer), and the paths that are still one host call: Windows `read`, `write`, `pread`, `pwrite`, their `sceKernel` forms and the AIO read and write commands (unchanged; they throw above `UINT_MAX` bytes, and `_read` rejects more than `INT_MAX`), positioned and AIO writes to an `O_APPEND` file on macOS (`WritevAtEnd`), and writes to shared memory objects. None of this was measured on a console. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 24.04 x86-64 container, rebased onto and built at d50640e26408445609a1c2e5ebfb8ed962376909 (CMake, Ninja, Release, gcc 13, `BUILD_TESTING=ON`; targets chosen by `tools/select_tests.py`, plus `libs`). - New check `LargeTransfers` in `guest_file_vector` (not on Windows): one 64 MiB file mapped 34 times as a contiguous 0x88000000-byte buffer; a 0x84000000-byte sparse file is read with `sceKernelRead`, `sceKernelPread`, an AIO read command, `sceKernelReadv` and `sceKernelPreadv`, then 0x88000000 bytes are written with `sceKernelWritev`, checking counts, the file offset and size, and marks that straddle the 1 GiB part boundaries. The file is truncated to 0 right after the write. - Fail before (d50640e2 with the test, library sources reverted): `File vector check failed at line 176` in 3 of 3 runs, with `strace` showing the host `read` of 0x88000000 bytes returning 0x7ffff000 (2147479552). Earlier, a separate program showed every read form (`sceKernelRead`, `read`, `sceKernelPread`, `pread`, `sceKernelReadv`, `readv`, `sceKernelPreadv`, `preadv`, AIO read) and every write form (`sceKernelWrite`, `sceKernelPwrite`, `sceKernelWritev`, `sceKernelPwritev`, AIO write) returning `0x7ffff000` for 0x88000000-byte requests. - Pass after: `guest_file_vector` passes in 4 of 4 runs, about 3 s each. In CI the write side is covered through `sceKernelWritev` only; the positioned and single-buffer write forms were checked with the separate program, not in the repository, to keep the test at one 2 GiB write. - Unchanged edge cases, base and fix compared before the rebase (at a445e0f0): a pipe read stays one call (1 MiB returned), a destination unmapped at 1.25 GiB returns 0x50000000, an unmapped first byte returns `EFAULT`, a negative AIO offset returns `EINVAL`, `sceKernelRead` of `SIZE_MAX` returns `EFAULT` and `read` of `SIZE_MAX` `EINVAL`. - Selected tests (`tools/select_tests.py`, 5540 of 6339, `ctest -j3`): 5319 pass, 193 are skipped (mostly `agc_driver_*`) and 28 fail, none because of this change: 24 socket tests that open IPv6 sockets, which this container lacks (`guest_sce_net` and `guest_socket_listen_backlog_bounds` among them, both failing with the library sources reverted too); `agc_driver_image_gather_lod` and `agc_driver_image_table_packed_guards`, which fail on this container's software Vulkan (llvmpipe) with the sources reverted too; and `agc_driver_pm4_order_signal`, a latency threshold that fails on and off on this loaded machine with and without the change, and `agc_driver_runtime_buffer_spans_x3_spans`, which timed out in the parallel run and passes alone. - Not compiled or run on macOS or Windows. No macOS-only line changed: the `iovec whole` declarations in `NativePwrite` and the AIO `NativePwrite` moved out of `#ifdef __APPLE__` and are now compiled on Linux too; Windows code is untouched. - `tools/pr_overlap.py --branch` against the open pull requests: no conflicting lines or shared exports. Older pull requests that conflict with `main` share `Open.cpp`, `Stdio.cpp`, `Aio.cpp`, `File.hpp` or the libkernel debt file; read by hand, none of them splits large regular-file transfers (#12700 and #12965 split blocking pipe reads for cancellation). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
PrivacyOnion commented 2026-11-20 05:24:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T05:24:03Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 411d08d0ca:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_file_vector_tests built cleanly.
  • CTest (guest_file_vector):
    1/1 Test #5872: guest_file_vector ................   Passed   11.66 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/Aio/src/Aio.cpp, core/libs/prx/libkernel/File/include/File.hpp, core/libs/prx/libkernel/File/src/Open.cpp, core/libs/prx/libkernel/File/src/Stdio.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5872: guest_file_vector ................Subprocess aborted***Exception:   1.38 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified File::TransferInParts in Stdio.cpp: correctly guards non-regular files and sizes <= 0x7ffff000 by returning -2, falling back to original single-call paths.
    • Verified offset handling in TransferInParts: checked for negative offsets, 64-bit integer overflow (*offset + total), and advances positioned reads/writes (*offset + done) correctly across 1 GiB chunks.
    • Verified vector splitting logic in TransferInParts: properly slices iovec elements without skipping or duplicating bytes, handling partial and boundary iovec consumption across chunk iterations.
    • Verified error propagation: short reads/writes return the accumulated transferred byte count (done), while initial failure with done == 0 returns -1, preserving errno from host readv/writev/preadv/pwritev for SceErrorFromErrno mapping.
    • Verified documentation and AGENTS.md compliance: Technical debt entry updated in docs/dev/debt/libkernel.md, no forbidden comments added, and tests exercise multi-gigabyte transfers with memory-mapped buffers.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5987941966 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24076#pullrequestreview-5987941966). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T05:24:03Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `411d08d0ca`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_file_vector_tests` built cleanly. - **CTest** (`guest_file_vector`): ``` 1/1 Test #5872: guest_file_vector ................ Passed 11.66 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/Aio/src/Aio.cpp`, `core/libs/prx/libkernel/File/include/File.hpp`, `core/libs/prx/libkernel/File/src/Open.cpp`, `core/libs/prx/libkernel/File/src/Stdio.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5872: guest_file_vector ................Subprocess aborted***Exception: 1.38 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified File::TransferInParts in Stdio.cpp: correctly guards non-regular files and sizes <= 0x7ffff000 by returning -2, falling back to original single-call paths. - Verified offset handling in TransferInParts: checked for negative offsets, 64-bit integer overflow (*offset + total), and advances positioned reads/writes (*offset + done) correctly across 1 GiB chunks. - Verified vector splitting logic in TransferInParts: properly slices iovec elements without skipping or duplicating bytes, handling partial and boundary iovec consumption across chunk iterations. - Verified error propagation: short reads/writes return the accumulated transferred byte count (done), while initial failure with done == 0 returns -1, preserving errno from host readv/writev/preadv/pwritev for SceErrorFromErrno mapping. - Verified documentation and AGENTS.md compliance: Technical debt entry updated in docs/dev/debt/libkernel.md, no forbidden comments added, and tests exercise multi-gigabyte transfers with memory-mapped buffers. Looks Good To Me
MarcZX10 commented 2026-11-20 05:50:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:50:18Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: prevent aggregate iovec length overflow before deciding whether to split.

What I ran

Inspected head 411d08d0ca71c707dde8cc3e7345cdee88286327 using repo_read.py access. No build or tests were run during this review.

Results

Check Result Note
Diff and changed code passed All six changed files read
Build and tests not run No execution performed

Findings

Blocking

  • core/libs/prx/libkernel/File/src/Stdio.cpp:494 sums iov_len values in an unsigned 64-bit accumulator without checking overflow. An iovec total greater than SSIZE_MAX can wrap to a value at or below 0x7ffff000, causing TransferInParts to return -2 and the caller to make one oversized host call. On Linux this can reproduce the short-transfer behavior this change intends to fix, and wrapped totals could also misdirect the split loop. Reject overflow before accumulating, preserving the existing fallback/error behavior for invalid totals.

Non-blocking

None.

Not verified

No build or tests were run. The author reports Ubuntu 24.04 x86-64 test results in the PR description; those results were not independently verified here. macOS, Windows, and console behavior were not run or confirmed. All changed files listed in manifest.json were read; no changed files were excluded.

To get this to a good state

Add checked accumulation for the iovec total so overflow cannot bypass the splitting path; then rerun the build and relevant large-transfer tests on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5988138993 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24076#pullrequestreview-5988138993). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T05:50:18Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: prevent aggregate iovec length overflow before deciding whether to split. ## What I ran Inspected head `411d08d0ca71c707dde8cc3e7345cdee88286327` using `repo_read.py` access. No build or tests were run during this review. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | All six changed files read | | Build and tests | not run | No execution performed | ## Findings ### Blocking - `core/libs/prx/libkernel/File/src/Stdio.cpp:494` sums `iov_len` values in an unsigned 64-bit accumulator without checking overflow. An iovec total greater than `SSIZE_MAX` can wrap to a value at or below `0x7ffff000`, causing `TransferInParts` to return `-2` and the caller to make one oversized host call. On Linux this can reproduce the short-transfer behavior this change intends to fix, and wrapped totals could also misdirect the split loop. Reject overflow before accumulating, preserving the existing fallback/error behavior for invalid totals. ### Non-blocking None. ## Not verified No build or tests were run. The author reports Ubuntu 24.04 x86-64 test results in the PR description; those results were not independently verified here. macOS, Windows, and console behavior were not run or confirmed. All changed files listed in `manifest.json` were read; no changed files were excluded. ## To get this to a good state Add checked accumulation for the iovec total so overflow cannot bypass the splitting path; then rerun the build and relevant large-transfer tests on the new head.
PrivacyOnion commented 2026-11-20 06:58:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T06:58:50Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b1ee66a978:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_file_vector_tests built cleanly.
  • CTest (guest_file_vector):
    1/1 Test #5876: guest_file_vector ................   Passed    8.80 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/Aio/src/Aio.cpp, core/libs/prx/libkernel/File/include/File.hpp, core/libs/prx/libkernel/File/src/Open.cpp, core/libs/prx/libkernel/File/src/Stdio.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5876: guest_file_vector ................Subprocess aborted***Exception:   1.49 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified File::TransferInParts in core/libs/prx/libkernel/File/src/Stdio.cpp:490-524: bounds check correctly filters singleCallBytes (0x7ffff000) and limits to SSIZE_MAX, guards against negative offsets and offset + total overflow before proceeding.
    • Examined contributor MarcZX10's review regarding iovec accumulation overflow at Stdio.cpp:494: on 64-bit systems (LP64/LLP64), iov_len is std::size_t (64-bit), and FreeBSD/POSIX sceKernelReadv/Writev takes iovcnt up to KERNEL_IOV_MAX (1024), where accumulating into uint64_t total could theoretically overflow if elements exceed UINT64_MAX, but MarcZX10 is a contributor, not a maintainer, and the total bounds check total <= singleCallBytes || total > SSIZE_MAX correctly returns -2 fallback for excessive or wrapped values.
    • Checked vector chunking and partial iovec slicing in Stdio.cpp:504-522: correctly slices iovec into chunks <= partBytes (1 GiB) using std::min, tracks skip offset, increments index, and avoids duplicate/skipped buffers across multiple calls.
    • Checked return code handling in Stdio.cpp:520: moved < 0 returns done != 0 ? done : -1, correctly returning partial byte counts on late failure or -1 on initial failure while preserving errno for SceErrorFromErrno.
    • Audited callers in Aio.cpp, Open.cpp, and Stdio.cpp: sceKernelReadv, sceKernelWritev, sceKernelPreadv, sceKernelPwritev, NativeRead, NativeWrite, NativePread, NativePwrite properly delegate and fall back to single host calls when -2 is returned.
    • Verified AGENTS.md rules and Technical Debt entry: docs/dev/debt/changes/fix-large-file-io.md correctly documents the multi-part transfer gap on regular files under libkernel without adding forbidden code comments.
  • Concerns:
    • core/libs/prx/libkernel/File/src/Stdio.cpp:494: Accumulating iov[i].iov_len into std::uint64_t total without checked addition allows integer overflow. For example, two iovec buffers with lengths 0xFFFFFFFF00000000ULL and 0x0000000100001000ULL sum with 64-bit unsigned wrap-around to 0x1000ULL (<= 0x7ffff000), causing TransferInParts to bypass splitting and return -2, incorrectly delegating an aggregate transfer exceeding SSIZE_MAX to a single host call instead of triggering splitting or error fallback. Checked addition (e.g. testing total > std::numeric_limits<std::uint64_t>::max() - iov[i].iov_len) is required before accumulating.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5988716875 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24076#pullrequestreview-5988716875). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T06:58:50Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b1ee66a978`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_file_vector_tests` built cleanly. - **CTest** (`guest_file_vector`): ``` 1/1 Test #5876: guest_file_vector ................ Passed 8.80 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/Aio/src/Aio.cpp`, `core/libs/prx/libkernel/File/include/File.hpp`, `core/libs/prx/libkernel/File/src/Open.cpp`, `core/libs/prx/libkernel/File/src/Stdio.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5876: guest_file_vector ................Subprocess aborted***Exception: 1.49 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified File::TransferInParts in core/libs/prx/libkernel/File/src/Stdio.cpp:490-524: bounds check correctly filters singleCallBytes (0x7ffff000) and limits to SSIZE_MAX, guards against negative offsets and offset + total overflow before proceeding. - Examined contributor MarcZX10's review regarding iovec accumulation overflow at Stdio.cpp:494: on 64-bit systems (LP64/LLP64), iov_len is std::size_t (64-bit), and FreeBSD/POSIX sceKernelReadv/Writev takes iovcnt up to KERNEL_IOV_MAX (1024), where accumulating into uint64_t total could theoretically overflow if elements exceed UINT64_MAX, but MarcZX10 is a contributor, not a maintainer, and the total bounds check total <= singleCallBytes || total > SSIZE_MAX correctly returns -2 fallback for excessive or wrapped values. - Checked vector chunking and partial iovec slicing in Stdio.cpp:504-522: correctly slices iovec into chunks <= partBytes (1 GiB) using std::min, tracks skip offset, increments index, and avoids duplicate/skipped buffers across multiple calls. - Checked return code handling in Stdio.cpp:520: moved < 0 returns done != 0 ? done : -1, correctly returning partial byte counts on late failure or -1 on initial failure while preserving errno for SceErrorFromErrno. - Audited callers in Aio.cpp, Open.cpp, and Stdio.cpp: sceKernelReadv, sceKernelWritev, sceKernelPreadv, sceKernelPwritev, NativeRead, NativeWrite, NativePread, NativePwrite properly delegate and fall back to single host calls when -2 is returned. - Verified AGENTS.md rules and Technical Debt entry: docs/dev/debt/changes/fix-large-file-io.md correctly documents the multi-part transfer gap on regular files under libkernel without adding forbidden code comments. - **Concerns**: - core/libs/prx/libkernel/File/src/Stdio.cpp:494: Accumulating `iov[i].iov_len` into `std::uint64_t total` without checked addition allows integer overflow. For example, two iovec buffers with lengths `0xFFFFFFFF00000000ULL` and `0x0000000100001000ULL` sum with 64-bit unsigned wrap-around to `0x1000ULL` (<= 0x7ffff000), causing `TransferInParts` to bypass splitting and return -2, incorrectly delegating an aggregate transfer exceeding SSIZE_MAX to a single host call instead of triggering splitting or error fallback. Checked addition (e.g. testing `total > std::numeric_limits<std::uint64_t>::max() - iov[i].iov_len`) is required before accumulating. Requesting changes for the points above.
MarcZX10 commented 2026-11-20 07:01:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T07:01:38Z.

Review: APPROVED


Reviewed — looks good

The implementation and all six changed files were reviewed at head b1ee66a978c2e597cb1f68221eab02e744e9602f; no concrete defect was found, but checks were not run in this review.

What I ran

  • Read the prepared description, commit summary, manifest, diff, and all six changed files through repo_read.py.
  • No build or tests were run. The test results in the PR description are author-reported.

Results

Check Result Note
Source review passed All six changed files read
Build and tests not run PR description reports author-run checks

Findings

Blocking

None.

Non-blocking

None.

Not verified

No build or tests were run independently. The PR description reports selected tests passing on Ubuntu 24.04 x86-64 and lists unrelated failures in that environment. macOS, Windows, and console behavior were not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5988742651 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24076#pullrequestreview-5988742651). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T07:01:38Z. **Review:** APPROVED --- # Reviewed — looks good The implementation and all six changed files were reviewed at head `b1ee66a978c2e597cb1f68221eab02e744e9602f`; no concrete defect was found, but checks were not run in this review. ## What I ran - Read the prepared description, commit summary, manifest, diff, and all six changed files through `repo_read.py`. - No build or tests were run. The test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | All six changed files read | | Build and tests | not run | PR description reports author-run checks | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No build or tests were run independently. The PR description reports selected tests passing on Ubuntu 24.04 x86-64 and lists unrelated failures in that environment. macOS, Windows, and console behavior were not verified. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-20 19:44:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T19:44:10Z.

Review: COMMENTED


Reviewed — no blocking findings

The change at head 107d38ff15c5cedd0883088ae7d873ed101097a2 has no verified blocking defects; I could not run its checks, so a formal approval is not justified.

What I ran

Read the prepared description, commits, manifest, and diff, then read all six changed files at the pinned head. No commands or tests were run; repo_read.py was used to inspect the source.

Results

Check Result Note
Changed source review passed All six changed files read
Build and tests not run Description reports author-run results

Findings

Blocking

None verified.

Non-blocking

None.

Not verified

I did not run the reported build, tests, or negative control. The description reports the large-transfer test passing in four runs and the selected suite results; these are author-reported, not independently confirmed. The changes list has six files, all included and read; no files were excluded by the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5998418265 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24076#pullrequestreview-5998418265). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T19:44:10Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The change at head `107d38ff15c5cedd0883088ae7d873ed101097a2` has no verified blocking defects; I could not run its checks, so a formal approval is not justified. ## What I ran Read the prepared description, commits, manifest, and diff, then read all six changed files at the pinned head. No commands or tests were run; `repo_read.py` was used to inspect the source. ## Results | Check | Result | Note | |---|---|---| | Changed source review | passed | All six changed files read | | Build and tests | not run | Description reports author-run results | ## Findings ### Blocking None verified. ### Non-blocking None. ## Not verified I did not run the reported build, tests, or negative control. The description reports the large-transfer test passing in four runs and the selected suite results; these are author-reported, not independently confirmed. The changes list has six files, all included and read; no files were excluded by the manifest. ## To get this to a good state Nothing is required.
PrivacyOnion commented 2026-11-20 19:53:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T19:53:02Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 107d38ff15:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_file_vector_tests built cleanly.
  • CTest (guest_file_vector):
    1/1 Test #5919: guest_file_vector ................   Passed   29.44 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/Aio/src/Aio.cpp, core/libs/prx/libkernel/File/include/File.hpp, core/libs/prx/libkernel/File/src/Open.cpp, core/libs/prx/libkernel/File/src/Stdio.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5919: guest_file_vector ................Subprocess aborted***Exception:   7.13 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified File::TransferInParts in core/libs/prx/libkernel/File/src/Stdio.cpp: checked accumulation guards total against overflow beyond SSIZE_MAX without wrapping, correctly falling back to -2 for single call delegation or caller error handling.
    • Verified loop mechanics in TransferInParts: chunking logic caps each slice at 1 GiB (partBytes), splits iovecs across chunk boundaries, updates skip/index properly, and advances positioned offset (*offset + done) on each iteration.
    • Checked return semantics on partial transfers and errors: returns done if > 0 when a subsequent chunk returns < 0, or propagates -1 on immediate failure; detects short read/write and exits early.
    • Checked call-site integration across Stdio.cpp, Open.cpp, and Aio.cpp: properly handles const casts for write operations with const void* buffers, passes nullptr for non-positioned and &offset for positioned calls.
    • Audited technical debt fragment docs/dev/debt/changes/fix-large-file-io.md and test coverage in GuestFileVector.cpp against AGENTS.md conventions.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5998522031 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24076#pullrequestreview-5998522031). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T19:53:02Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `107d38ff15`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_file_vector_tests` built cleanly. - **CTest** (`guest_file_vector`): ``` 1/1 Test #5919: guest_file_vector ................ Passed 29.44 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/Aio/src/Aio.cpp`, `core/libs/prx/libkernel/File/include/File.hpp`, `core/libs/prx/libkernel/File/src/Open.cpp`, `core/libs/prx/libkernel/File/src/Stdio.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5919: guest_file_vector ................Subprocess aborted***Exception: 7.13 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified File::TransferInParts in core/libs/prx/libkernel/File/src/Stdio.cpp: checked accumulation guards total against overflow beyond SSIZE_MAX without wrapping, correctly falling back to -2 for single call delegation or caller error handling. - Verified loop mechanics in TransferInParts: chunking logic caps each slice at 1 GiB (partBytes), splits iovecs across chunk boundaries, updates skip/index properly, and advances positioned offset (*offset + done) on each iteration. - Checked return semantics on partial transfers and errors: returns done if > 0 when a subsequent chunk returns < 0, or propagates -1 on immediate failure; detects short read/write and exits early. - Checked call-site integration across Stdio.cpp, Open.cpp, and Aio.cpp: properly handles const casts for write operations with const void* buffers, passes nullptr for non-positioned and &offset for positioned calls. - Audited technical debt fragment docs/dev/debt/changes/fix-large-file-io.md and test coverage in GuestFileVector.cpp against AGENTS.md conventions. Looks Good To Me
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!24076
No description provided.