Skip to content

checksum: accept base64 digests only in cksum --check - #16742

Merged
sylvestre merged 2 commits into
uutils:mainfrom
ChihweiLHBird:zhiwei/checksum-check-reject-base64
Nov 27, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
ChihweiLHBird:zhiwei/checksum-check-reject-base64

Conversation

@ChihweiLHBird

Copy link
Copy Markdown
Contributor

Summary

md5sum, sha*sum and b2sum read a base64 digest in --check. GNU reads base64 only in cksum, and reports such a line as improperly formatted in the other tools.

Example

$ printf 'a\n' > a
$ printf 'YLcl8QychccNl4gN/oGRsw==  a\n' | md5sum --check

Before:

a: OK

After, same as GNU:

md5sum: 'standard input': no properly formatted checksum lines found

Copilot AI balanced review requested due to automatic review settings November 21, 2026 04:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codspeed

codspeed Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 126 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

✅ 415 untouched benchmarks
⏩ 70 skipped benchmarks1


Comparing ChihweiLHBird:zhiwei/checksum-check-reject-base64 (cb2a3d6) with main (932efe9)2

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (6dcc23e) during the generation of this report, so 932efe9 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Comment thread src/uu/checksum_common/src/lib.rs Outdated
let verbose = ChecksumVerbose::new(status, quiet, warn);
let opts = ChecksumValidateOptions {
allow_empty_filename,
allow_base64_digest,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding New variable for this is hacky for me. md5sum --ckeck already have a logic to reject non-md5. No?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @oech3, thanks for the review! I don't think there is any current logic for rejecting base64 encoding. The existing logic checks the decoded digest, but not the encoding format.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does current md5sum --ckeck rejects b2sum as input?

@ChihweiLHBird ChihweiLHBird Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oech3 The check that rejects b2sum compares the size of the decoded digest. A base64 MD5 digest decodes to 16 bytes, the same as a hex one, so it passes that check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decoding happens before the size check that rejects b2sum, so that check only sees the decoded bytes:

base64_simd::forgiving_decode_to_vec(checksum.as_bytes())
.ok()
.filter(|raw| checks_hint(raw.len()))

@ChihweiLHBird
ChihweiLHBird requested a review from oech3 November 21, 2026 07:01
@RenjiSann

Copy link
Copy Markdown
Collaborator

In this case, I'll admit I'm not sure it's worth adding complexity to the existing code to basically regress the capability of our version just to match with GNU.

@oech3

oech3 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Checking a non-md5 by md5sum binary is a bug. We should fix it. But I think current approach is hacky.

@sylvestre

Copy link
Copy Markdown
Contributor

maybe too many bool ?

@xtqqczze

This comment was marked as resolved.

@ChihweiLHBird

Copy link
Copy Markdown
Contributor Author

In this case, I'll admit I'm not sure it's worth adding complexity to the existing code to basically regress the capability of our version just to match with GNU.

It's not just a feature removal for matching GNU, but also a fix of an hidden bug of wrong result with plain hex input:

$ printf 'a\n' > a
$ sha256sum a | sha384sum --check

main:

a: FAILED
sha384sum: WARNING: 1 computed checksum did NOT match

GNU and this PR:

sha384sum: 'standard input': no properly formatted checksum lines found

The reason is that the 64 hex digits also happen to be valid base64 for 48 bytes, so code in main branch accepts the line as a SHA-384 digest and then reports FAILED because those bytes do not match the file.

@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/checksum-check-reject-base64 branch from 0a64f50 to 32fe634 Compare November 21, 2026 18:01
Copilot AI balanced review requested due to automatic review settings November 21, 2026 18:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@ChihweiLHBird

Copy link
Copy Markdown
Contributor Author

maybe too many bool ?

Agreed. I will try another design that replacing both bools with one enum for the tool (cksum / b2sum / the others). Let's see if that would work?

@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/checksum-check-reject-base64 branch from 32fe634 to d2dfb94 Compare November 21, 2026 18:12
Copilot AI balanced review requested due to automatic review settings November 21, 2026 18:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@ChihweiLHBird

Copy link
Copy Markdown
Contributor Author

Checking a non-md5 by md5sum binary is a bug. We should fix it. But I think current approach is hacky.

The base64 decode, hash, and comparison logic are shared among all the binaries of check sum, so the way to fix it is passing through the difference of each tool down to the shared function.

I pushed another style to pass an enum rather than boolean. Does it sound like a better way to you?

@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/checksum-check-reject-base64 branch from d2dfb94 to 8a92388 Compare November 22, 2026 03:07
Copilot AI balanced review requested due to automatic review settings November 22, 2026 03:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@ChihweiLHBird
ChihweiLHBird requested a review from oech3 November 22, 2026 03:30
@sylvestre
sylvestre force-pushed the zhiwei/checksum-check-reject-base64 branch from 8a92388 to e584ca5 Compare November 23, 2026 16:30
Copilot AI balanced review requested due to automatic review settings November 23, 2026 16:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/checksum-check-reject-base64 branch from e584ca5 to 570a6e3 Compare November 24, 2026 08:09
Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/checksum-check-reject-base64 branch from 570a6e3 to b7aa5e9 Compare November 24, 2026 17:23
Copilot AI balanced review requested due to automatic review settings November 24, 2026 17:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/checksum-check-reject-base64 branch from b7aa5e9 to 1bcee41 Compare November 26, 2026 07:46
Copilot AI balanced review requested due to automatic review settings November 26, 2026 07:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

ChecksumTool names the utility that reads the checksum list, and the
rule for an empty file name is now a method of it. The behaviour does
not change.

Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
md5sum, sha*sum and b2sum read a base64 digest in --check, so a line
that GNU reports as improperly formatted gave OK or FAILED. Only cksum
reads base64 now, as in GNU.

Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
@ChihweiLHBird
ChihweiLHBird force-pushed the zhiwei/checksum-check-reject-base64 branch from 1bcee41 to cb2a3d6 Compare November 27, 2026 11:14
Copilot AI balanced review requested due to automatic review settings November 27, 2026 11:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@sylvestre
sylvestre merged commit a8209e0 into uutils:main Nov 27, 2026
196 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

@ChihweiLHBird
ChihweiLHBird deleted the zhiwei/checksum-check-reject-base64 branch November 27, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants