Skip to content

Commit

Permalink
cksum: fix failure to diagnose read errors with crc32
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pixelb committed Apr 24, 2023
1 parent e29f441 commit 9d333ac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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".]
Expand Down
8 changes: 1 addition & 7 deletions src/cksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions src/cksum_pclmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}

0 comments on commit 9d333ac

Please sign in to comment.