4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-21 00:07:36 +08:00

Cygwin: lseek: fix an off-by-one condition in SEEK_DATA/SEEK_HOLE

The conditional checking if lseek should return ENXIO checks the
offset being bigger than the current filesize, but accidentally not
for being equal to the current filesize.

This can lead to an endless loop in newer versions of cp(1).

Fixes: edfa581d3c5a7 ("Cygwin: lseek: implement SEEK_DATA and SEEK_HOLE for files")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2025-02-14 15:10:01 +01:00
parent 6363caef2d
commit fac7441835
2 changed files with 10 additions and 1 deletions

View File

@ -1144,7 +1144,7 @@ fhandler_base::lseek (off_t offset, int whence)
return -1;
}
/* Per Linux man page, ENXIO if offset is beyond EOF */
if (offset > fsi.EndOfFile.QuadPart)
if (offset >= fsi.EndOfFile.QuadPart)
{
set_errno (ENXIO);
return -1;

View File

@ -112,3 +112,12 @@ What changed:
explicitly in Cygwin will now also show up as mounted under the
cygdrive prefix, whereas before that entry would have been suppressed.
Addresses: https://cygwin.com/pipermail/cygwin/2024-June/256081.html
Fixes:
------
- Fix an off-by-one bug in lseek(2)'s SEEK_DATA/SEEK_HOLE handling on
filesystem-compressed files, potentially triggering a hang in cp(1).
Addresses: https://sourceware.org/pipermail/cygwin/2025-January/257082.html
https://cygwin.com/pipermail/cygwin/2025-February/257326.html