]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
wc: fix regression determining file size
authorPádraig Brady <P@draigBrady.com>
Wed, 28 Dec 2022 14:04:19 +0000 (14:04 +0000)
committerPádraig Brady <P@draigBrady.com>
Thu, 29 Dec 2022 14:15:54 +0000 (14:15 +0000)
* src/wc.c (wc): Use off_t rather than size_t
when calculating where to seek to, so that
we don't seek to a too low offset on systems
where size_t < off_t, which would result in
many read() calls to determine the file size.
* tests/misc/wc-proc.sh: Add a test case
sufficient for 32 bit systems at least.
* NEWS: Mention the bug fix.
Reported at https://bugs.debian.org/1027101

NEWS
src/wc.c
tests/misc/wc-proc.sh

diff --git a/NEWS b/NEWS
index b6b5201e7c74f143bf4fbd2e8db7a81d714eb21e..7fb8c5363f49cf9e7ceb832db8abc2d3fcaf1bff 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,11 @@ GNU coreutils NEWS                                    -*- outline -*-
   and the system supported set of valid speeds.
   [This bug was present in "the beginning".]
 
+  `wc -c` will again efficiently determine the size of large files
+  on all systems.  It no longer redundantly reads data from certain
+  sized files larger than SIZE_MAX.
+  [bug introduced in coreutils-8.24]
+
 ** Changes in behavior
 
   'cp --reflink=always A B' no longer leaves behind a newly created
index bc52a8c0ea59c3708d5d06193a03404df33738a7..df9770396a07d1a206d78d30355d20ccc5be68a0 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
@@ -431,7 +431,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos)
       if (! fstatus->failed && usable_st_size (&fstatus->st)
           && 0 <= fstatus->st.st_size)
         {
-          size_t end_pos = fstatus->st.st_size;
+          off_t end_pos = fstatus->st.st_size;
           if (current_pos < 0)
             current_pos = lseek (fd, 0, SEEK_CUR);
 
index 581890ddd18d046a0c7851c529cacf0845491907..030872a91b24ef75970ee01b905ec95b490a0ace 100755 (executable)
@@ -42,4 +42,11 @@ cat <<\EOF > exp
 EOF
 compare exp out || fail=1
 
+# Ensure we don't read too much when reading,
+# as was the case on 32 bit systems
+# from coreutils-8.24 to coreutils-9.1
+if timeout 10 truncate -s1T do_read; then
+  timeout 10 wc -c do_read || fail=1
+fi
+
 Exit $fail