cksum: support mixed reversed format checksum files

* src/cksum.c (digest_check): Reset the detection flag per file.
* tests/cksum/cksum-c.sh: Add a test case.
* tests/cksum/md5sum-bsd.sh: Likwise.
* NEWS: Mention the fix.
This commit is contained in:
Pádraig Brady committed 2026-10-27 23:15:56 +00:00
1 parent 1ca499910a
commit 119cabc8a1
4 files changed
+18 -1

No files matched your search

+6
View File
@@ -12,6 +12,12 @@ GNU coreutils NEWS -*- outline -*-
was used, even when the look-up inside the chroot succeeded.
[bug introduced in coreutils-8.23]
'cksum' now detects GNU and BSD reversed formats for each checksum file.
Previously mixing these formats across files could reject valid checksums
or incorrectly interpret a space as part of a file name.
This also applies to the md5sum, sha*sum, and b2sum utilities.
[bug introduced in coreutils-8.14]
'cksum --check' now rejects length suffixes on fixed-length algorithm tags,
such as SHA256-8. Previously these caused only part of the digest to be
checked, and could cause subsequent full-length untagged checksums to be
+1
View File
@@ -1397,6 +1397,7 @@ digest_check (char const *checkfile_name)
}
}
bsd_reversed = -1;
line_number = 0;
line = NULL;
line_chars_allocated = 0;
+6
View File
@@ -22,6 +22,12 @@ uses_strace_
shuf -i 1-10 > input || framework_failure_
# Detect GNU and BSD reversed formats independently for each checksum file.
cksum -a sha256 --untagged input > standard.sum || framework_failure_
sed 's/ input$/ input/' standard.sum > reversed.sum || framework_failure_
cksum -a sha256 --strict --check standard.sum reversed.sum || fail=1
cksum -a sha256 --strict --check reversed.sum standard.sum || fail=1
for args in '-a sha2 -l 384' '-a blake2b' '-a blake2b -l 384' '-a sm3'; do
cksum $args 'input' >> CHECKSUMS || fail=1
done
+5 -1
View File
@@ -32,10 +32,14 @@ for i in 'a' ' b' '*c' 'dd' ' '; do
done
sed 's/ / /' check.md5sum > check.md5
# Note only a single format is supported per run
# Note only a single untagged format is supported per checksum file.
md5sum --strict -c check.md5sum || fail=1
md5sum --strict -c check.md5 || fail=1
# The format of one checksum file must not affect parsing of the next.
md5sum --strict -c check.md5sum check.md5 || fail=1
md5sum --strict -c check.md5 check.md5sum || fail=1
# Ensure we don't trigger BSD reversed format with GPG headers etc.
{ echo '____not_all_hex_so_no_match_____ blah';
cat check.md5sum; } > check2.md5sum || framework_failure_