Skip to content

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

Open
ChihweiLHBird wants to merge 1 commit into
uutils:mainfrom
ChihweiLHBird:zhiwei/checksum-check-reject-base64
Open

ChihweiLHBird wants to merge 1 commit 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

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>
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 improve performance by 4.33%

3 warnings, 1 note

⚠️ 120 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 with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark with a significant change ran in a different software environment

Its base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the change might come from this difference rather than from the code. Open the benchmark to see what changed.

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

⚡ 1 improved benchmark
✅ 412 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation df_deep_directory 930.1 µs 891.5 µs +4.33%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ChihweiLHBird:zhiwei/checksum-check-reject-base64 (0a64f50) with main (2775292)

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. ↩

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

This branch has not been deployed

No deployments
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.

3 participants