[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] wc: fix regression determining file size
From: |
Pádraig Brady |
Subject: |
[PATCH] wc: fix regression determining file size |
Date: |
Wed, 28 Dec 2022 14:11:13 +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.
Reported at https://bugs.debian.org/1027101
---
src/wc.c | 2 +-
tests/misc/wc-proc.sh | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/wc.c b/src/wc.c
index bc52a8c0e..df9770396 100644
--- 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);
diff --git a/tests/misc/wc-proc.sh b/tests/misc/wc-proc.sh
index 581890ddd..030872a91 100755
--- a/tests/misc/wc-proc.sh
+++ b/tests/misc/wc-proc.sh
@@ -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
--
2.26.2
- [PATCH] wc: fix regression determining file size,
Pádraig Brady <=