https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=fac7441835b00d3b9a8252538bcf54c441c3841e

commit fac7441835b00d3b9a8252538bcf54c441c3841e
Author:     Corinna Vinschen <[email protected]>
AuthorDate: Fri Feb 14 15:10:01 2025 +0100
Commit:     Corinna Vinschen <[email protected]>
CommitDate: Fri Feb 14 15:10:01 2025 +0100

    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 <[email protected]>
    Signed-off-by: Corinna Vinschen <[email protected]>

Diff:
---
 winsup/cygwin/fhandler/base.cc | 2 +-
 winsup/cygwin/release/3.6.0    | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler/base.cc b/winsup/cygwin/fhandler/base.cc
index 8f3dbd4ed51a..79dfaaa5987a 100644
--- a/winsup/cygwin/fhandler/base.cc
+++ b/winsup/cygwin/fhandler/base.cc
@@ -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;
diff --git a/winsup/cygwin/release/3.6.0 b/winsup/cygwin/release/3.6.0
index 5869d7ffc842..3f0fb6044395 100644
--- a/winsup/cygwin/release/3.6.0
+++ b/winsup/cygwin/release/3.6.0
@@ -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

Reply via email to