fix(libkernel): return EOVERFLOW from lseek on 64-bit offset overflow #5325

Closed
Kikoarl wants to merge 1 commit from upstream-pr/5325 into main
Kikoarl commented 2026-10-13 17:17:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T17:17:44Z.


What

FreeBSD 11.4 vn_seek returns EOVERFLOW when a relative seek with SEEK_CUR or SEEK_END overflows a 64-bit signed offset (INT64_MAX), keeping EINVAL for seeks that land before the start of the file.

When NativeLseek fails with EINVAL on a positive relative offset, compute base plus offset and return EOVERFLOW (0x80020054 for sceKernelLseek, errno = 84 for lseek) if the computation overflows, otherwise preserving errno.

Closes #5248

Tested

  • Linux (x86_64), GCC 16, Release, RAM-disk build (/tmp/anyps5_build).
  • Passes ctest -R guest_lseek_overflow: verifies SEEK_CUR and SEEK_END overflow cases returning EOVERFLOW, negative seeks returning EINVAL, and seeks near INT64_MAX.
  • Passes ctest -R "guest_kernel_fcntl|guest_file_vector".
  • Passes python3 tools/check_conventions.py.

Checklist

  • Description explains the problem and the change
  • PR follows CONTRIBUTING.md
  • Changes are covered by tests
  • Code passes python3 tools/check_conventions.py
  • Tech debt documented in docs/dev/TechnicalDebt.md (if applicable)
  • AI-assisted: yes
  • Depends on: none
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4846864155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5325). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T17:17:44Z. --- ### What FreeBSD 11.4 `vn_seek` returns `EOVERFLOW` when a relative seek with `SEEK_CUR` or `SEEK_END` overflows a 64-bit signed offset (`INT64_MAX`), keeping `EINVAL` for seeks that land before the start of the file. When `NativeLseek` fails with `EINVAL` on a positive relative offset, compute base plus offset and return `EOVERFLOW` (`0x80020054` for `sceKernelLseek`, `errno = 84` for `lseek`) if the computation overflows, otherwise preserving `errno`. Closes #5248 ### Tested - Linux (x86_64), GCC 16, Release, RAM-disk build (`/tmp/anyps5_build`). - Passes `ctest -R guest_lseek_overflow`: verifies `SEEK_CUR` and `SEEK_END` overflow cases returning `EOVERFLOW`, negative seeks returning `EINVAL`, and seeks near `INT64_MAX`. - Passes `ctest -R "guest_kernel_fcntl|guest_file_vector"`. - Passes `python3 tools/check_conventions.py`. ### Checklist - [x] Description explains the problem and the change - [x] PR follows [CONTRIBUTING.md](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONTRIBUTING.md) - [x] Changes are covered by tests - [x] Code passes `python3 tools/check_conventions.py` - [x] Tech debt documented in `docs/dev/TechnicalDebt.md` (if applicable) - [x] AI-assisted: yes - [x] Depends on: none
github-actions[bot] commented 2026-10-13 17:24:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T17:24:04Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5008 core/libs/prx/libkernel/CMakeLists.txt L1212
#5265 core/libs/prx/libkernel/CMakeLists.txt L1212
#5274 core/libs/tests/GuestLseekOverflow.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151236390 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5325#issuecomment-6151236390). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T17:24:04Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5008 | `core/libs/prx/libkernel/CMakeLists.txt` [L1212](https://github.com/boykopovar/AnyPS5/blob/8cf6a0bc3a17782e8f1063d1127f72419260230b/core/libs/prx/libkernel/CMakeLists.txt#L1212) | | | | #5265 | `core/libs/prx/libkernel/CMakeLists.txt` [L1212](https://github.com/boykopovar/AnyPS5/blob/8cf6a0bc3a17782e8f1063d1127f72419260230b/core/libs/prx/libkernel/CMakeLists.txt#L1212) | | | | #5274 | | | `core/libs/tests/GuestLseekOverflow.cpp` |
Kikoarl commented 2026-10-13 17:38:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T17:38:28Z.


Closing in favor of earlier carry in #5274.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151492217 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5325#issuecomment-6151492217). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T17:38:28Z. --- Closing in favor of earlier carry in #5274.

Pull request closed

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!5325
No description provided.