]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: fix failure to diagnose read errors with crc32
authorPádraig Brady <P@draigBrady.com>
Sat, 22 Apr 2023 14:59:48 +0000 (15:59 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 24 Apr 2023 10:46:28 +0000 (11:46 +0100)
The default crc32 mode fails to diagnose read errors.

* src/cksum.c (cksum_slice8): Fix the check for read errors.
(cksum_pclmul): Likewise.
* NEWS: Mention the bug fix.

NEWS
src/cksum.c
src/cksum_pclmul.c

diff --git a/NEWS b/NEWS
index 8edfa8080e28907eee92c69ef3404bb4d0edb79d..a8db32246b64793dee1c78cc6bdf242fef3ededa 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  cksum again diagnoses read errors in its default CRC32 mode.
+  [bug introduced in coreutils-9.0]
+
   install --strip now supports installing to files with a leading hyphen.
   Previously such file names would have caused the strip process to fail.
   [This bug was present in "the beginning".]
index 75d82e62cae2ebf8ef25187199745d468e02ea51..85afab0ac790dbaa51c7fd5f66167b4f5f0e200d 100644 (file)
@@ -212,12 +212,6 @@ cksum_slice8 (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
         }
       length += bytes_read;
 
-      if (bytes_read == 0)
-        {
-          if (ferror (fp))
-            return false;
-        }
-
       /* Process multiples of 8 bytes */
       datap = (uint32_t *)buf;
       while (bytes_read >= 8)
@@ -247,7 +241,7 @@ cksum_slice8 (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
   *crc_out = crc;
   *length_out = length;
 
-  return true;
+  return !ferror (fp);
 }
 
 /* Calculate the checksum and length in bytes of stream STREAM.
index 9c6e4df54d95297da78e4022caf69c8416580255..9dba1c91213e6e50c54266bbda2d3a67f971b199 100644 (file)
@@ -77,12 +77,6 @@ cksum_pclmul (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
         }
       length += bytes_read;
 
-      if (bytes_read == 0)
-        {
-          if (ferror (fp))
-            return false;
-        }
-
       datap = (__m128i *)buf;
 
       /* Fold in parallel eight 16-byte blocks into four 16-byte blocks */
@@ -191,5 +185,5 @@ cksum_pclmul (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
   *crc_out = crc;
   *length_out = length;
 
-  return true;
+  return !ferror (fp);
 }