libkernel: lseek returns EINVAL instead of EOVERFLOW when the new offset overflows 64 bits; fix branch ready #5248
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 husseinkad on 2026-10-13T15:34:40Z.
lseekandsceKernelLseekreturnEINVALfrom the host when a positive offset added to the current position (SEEK_CUR) or the file size (SEEK_END) overflows a signed 64-bit offset. FreeBSD 11.4vn_seekreturnsEOVERFLOWfor that case and keepsEINVALfor a seek that lands before the start of the file. A guest that distinguishes the two (a library that probes the maximum file offset, for example) sees the wrong error.Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/libkernel-lseek-eoverflow (three commits on a recent main: the change, a performance follow-up and a test cleanup from review;
File/src/Open.cppand the new testtests/GuestLseekOverflow.cpp, registered asguest_lseek_overflow). The host seek runs first; only when it fails withEINVALon a positive relative offset does the code compute base plus offset (the current position, orst_sizefromfstatforSEEK_END) and returnEOVERFLOWif that overflows, otherwise it restoreserrnoand returns the old result. The first version calledfstaton every seek and madelseek(SEEK_END, +1)about 9 times slower (48 µs against 5.4 µs per call); the final version keeps the success path at main's cost.Checks:
guest_kernel_fcntlandguest_file_vectorpass.vn_seekmodel (SEEK_SET,SEEK_CUR,SEEK_ENDat position 0, mid-file and end of file, an empty file and positions nearINT64_MAX, offsets 0, 1, max, max minus size plus or minus one, -1 and min) had zero mismatches. The only change from main isEINVALbecomingEOVERFLOW(84) in the overflow cases (18 of them). A failed seek leaves the position unchanged, andlseek(fd, 0, SEEK_CUR)afterwards is correct. Negative results stayEINVAL, a bad fd staysEBADF, and the directory, pipe, socket,/dev/nulland/dev/urandomresults match main. 100000SEEK_END +1calls took 405 ms on main and 464 to 492 ms on the final head on a busy machine.check_conventions.pyis clean;pr_overlap.pydid not finish within its timeout, and I found no open PR for it by hand (#4672 editsNativeLseekonly, in different lines).Not covered: the test needs a host seek near
INT64_MAX; where the host refuses that (ext4), it prints a skip line and runs only the checks that need no huge position, and that path was not run (only Windows was built and run). A directorylseekwithSEEK_ENDandINT64_MAXaborts the process on main as well, which this change does not touch.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T16:15:00Z.
Carried the fix in #5274, preserving Hussein Kadhim's original authorship. On Linux,
guest_lseek_overflow,guest_file_vector, andguest_kernel_fcntlpassed (3/3). The regression test aborts on currentmainwith errno 22 at the overflowing relative seek, then passes with the fix. I did not run Windows locally.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:54:28Z.
Closing: no title is known to reach this, and functions are only changed when a title needs them. #5274 is closed for the same reason. If a title stops on or misbehaves because of it on current main, comment here with the title ID and the log line.