Skip to content

Try to fix *sum on windows - #10761

Open
RenjiSann wants to merge 2 commits into
uutils:mainfrom
RenjiSann:fix-cksum-windows
Open

Try to fix *sum on windows#10761
RenjiSann wants to merge 2 commits into
uutils:mainfrom
RenjiSann:fix-cksum-windows

Conversation

@RenjiSann

Copy link
Copy Markdown
Collaborator

Attempt to fix #6655

@github-actions

github-actions Bot commented Feb 6, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/basenc/bounded-memory is now passing!

@RenjiSann

Copy link
Copy Markdown
Collaborator Author

@YDX-2147483647 @wu0lss4j Could you test with this branch if that fixes your problem ?

@YDX-2147483647

YDX-2147483647 commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Thank you for working on it!

Here're the results for a.fake-ttf + this PR on my machine.

❯ cargo r -r -- sha256sum a.fake-ttf
1c671d7322d49cd2726475f4b8a8b50f27b454789e23a31c6ac14014740d8e58  a.fake-ttf
❯ cargo r -r -- sha256sum --text a.fake-ttf
1c671d7322d49cd2726475f4b8a8b50f27b454789e23a31c6ac14014740d8e58  a.fake-ttf
❯ cargo r -r -- sha256sum --binary a.fake-ttf
1c671d7322d49cd2726475f4b8a8b50f27b454789e23a31c6ac14014740d8e58 *a.fake-ttf

❯ cargo r -r -- sha256sum --text a.fake-ttf | cargo r -r -- sha256sum --check
a.fake-ttf: OK
❯ cargo r -r -- sha256sum --binary a.fake-ttf | cargo r -r -- sha256sum --check
a.fake-ttf: OK

This PR fixes the problem of sha256sum --check, but also introduces unwanted changes.
Compare this PR with 0.5.0:

❯ coreutils --version
coreutils 0.5.0 (multi-call binary)
❯ coreutils sha256sum a.fake-ttf
1c671d7322d49cd2726475f4b8a8b50f27b454789e23a31c6ac14014740d8e58 *a.fake-ttf # 👈 I don't think `*` should be removed
❯ coreutils sha256sum --text a.fake-ttf
73c0a22f7ed1c54ebde921712ced33d9458975cd86e9fe4757257fdd6293e512  a.fake-ttf # 👈 I think this is the correct output, and should not be changed.
❯ coreutils sha256sum --binary a.fake-ttf
1c671d7322d49cd2726475f4b8a8b50f27b454789e23a31c6ac14014740d8e58 *a.fake-ttf # Unchanged and okay

Edit: Should the following fail?

❯ coreutils sha256sum --text a.fake-ttf | cargo r -r sha256sum --check
a.fake-ttf: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match

@RenjiSann

Copy link
Copy Markdown
Collaborator Author

This PR is not the reason for this unwanted behavior, sicne I only changed a piece of code that is run in --check mode only. I'll investigate

@RenjiSann

Copy link
Copy Markdown
Collaborator Author

Actually, that reopens the debate of --text and --binary handling #9168.

The "unwanted" behavior for cksum -a sha256 a.ttf is the one actually expected if we follow the GNU documentation

 ‘--binary’
...
This option is the default on systems like
MS-DOS that distinguish between binary and text files

At the time, we decided to ignore --binary as it didn't change the behavior on UNIX and GNU didn't work on Windows, but now I realize that we should still be coherent at least for the --check option.

@RenjiSann
RenjiSann marked this pull request as ready for review February 6, 2026 18:05
@github-actions

github-actions Bot commented Feb 7, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/env/env-signal-handler. tests/env/env-signal-handler is passing on 'main'. Maybe you have to rebase?

@wu0lss4j

wu0lss4j commented Feb 9, 2026

Copy link
Copy Markdown

@YDX-2147483647 @wu0lss4j Could you test with this branch if that fixes your problem ?

Hi, sorry for the delay, every test yields FAILED, sorry.

on version 0.6.0 of core-utils I get this:
0.6.0 --check fails still

checksum computed as -t and -b

checksum verification from a -t and -b computed checksum

@YDX-2147483647

YDX-2147483647 commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

@wu0lss4j v0.6.0 does not include changes made in this pull request. To test this pull request, you have to clone this branch and compile it with a rust toolchain.

Here's the coreutils.exe I compiled from the current version of this pull request.
coreutils-f5fc1a597.zip
(However, I cannot prove that it is not a virus. Use at your own risk.)

@wu0lss4j

wu0lss4j commented Feb 9, 2026

Copy link
Copy Markdown

@wu0lss4j v0.6.0 does not include changes made in this pull request. To test this pull request, you have to clone this branch and compile it with a rust toolchain.

Here's the coreutils.exe I compiled from the current version of this pull request.

coreutils-f5fc1a597.zip

(However, I cannot prove that it is not a virus. Use at your own risk.)

no worries, I trust your build and outcome. Meanwhile I got all my checksum needs serviced by the sha256sum binary that is bundled with the git package

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/pr/bounded-memory is no longer failing!

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/pr/bounded-memory. tests/pr/bounded-memory is passing on 'main'. Maybe you have to rebase?

@codspeed-hq

codspeed-hq Bot commented Feb 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 293 untouched benchmarks
⏩ 42 skipped benchmarks1


Comparing RenjiSann:fix-cksum-windows (718c317) with main (9ac174b)

Open in CodSpeed

Footnotes

  1. 42 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.

@sylvestre

Copy link
Copy Markdown
Contributor

@YDX-2147483647 @wu0lss4j Could you test with this branch if that fixes your problem ?

Hi, sorry for the delay, every test yields FAILED, sorry.

please replace your screenshots by text, they are not great for accessibility and search

@sylvestre

Copy link
Copy Markdown
Contributor

and would be nice to have a test

@wu0lss4j

wu0lss4j commented Feb 16, 2026

Copy link
Copy Markdown

@YDX-2147483647 @wu0lss4j Could you test with this branch if that fixes your problem ?

Hi, sorry for the delay, every test yields FAILED, sorry.

please replace your screenshots by text, they are not great for accessibility and search

OK, if and when there is a new release, I will test it and paste here the results in text form. However, it's quite easy to reproduce coreutils wintel binaries 0.6.0, run checksum, then run verification, I don't fully understand the math behind all the calculations, so I can't tell if the the issue is a faulty "recalculation" or just the easy peasy diff against the file that contains the list of checksum for the --check op

@atricap

atricap commented Feb 18, 2026

Copy link
Copy Markdown

Hey all,
I'm new here and not fluid at all with rust and handling github issues and PRs. So please forgive me, if I miss something.

Nevertheless, I hope I can help troubleshooting this issue, as I'm having the same problem.

tl;dr: Seems to be fine now with the patched coreutils.exe!

My setup: Current Windows 11, cmd, scoop with uutils-coreutils 0.5.0/0.6.0 (and several other packages).
For comparison purposes: WSL2 with Ubuntu 20.04.6 LTS.

I did some other testing with different line endings, and found "\r\n" to be problematic. But my main problem, which led me here, with coreutils 0.5.0, is this:

> sha256sum *.tar.gz > sha
> sha256sum -b *.tar.gz > sha-b
> sha256sum -t *.tar.gz > sha-t

> cat sha
733876246e1bb6171a2b849b5df8ce0f702139eb1c5842b2a610acce44651abf *2026-02-15_backup.tar.gz
> cat sha-b
733876246e1bb6171a2b849b5df8ce0f702139eb1c5842b2a610acce44651abf *2026-02-15_backup.tar.gz
> cat sha-t
717bbf87ab8d3de2b4b26fdc57cceb9b409832c30033c6497e7070b386b8d4fd  2026-02-15_backup.tar.gz

> sha256sum -c sha-b
2026-02-15_backup.tar.gz: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
> sha256sum -c sha-t
2026-02-15_backup.tar.gz: OK

sha and sha-b are bit-identical (comp sha sha-b). Manually comparing the hash with 7zip's sha256 context menu function matches sha-b.

Now the same with 0.6.0:

> cat sha
733876246e1bb6171a2b849b5df8ce0f702139eb1c5842b2a610acce44651abf  2026-02-15_backup.tar.gz
> cat sha-b
733876246e1bb6171a2b849b5df8ce0f702139eb1c5842b2a610acce44651abf *2026-02-15_backup.tar.gz
> cat sha-t
733876246e1bb6171a2b849b5df8ce0f702139eb1c5842b2a610acce44651abf  2026-02-15_backup.tar.gz

> sha256sum -c sha-b
2026-02-15_backup.tar.gz: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
> sha256sum -c sha-t
2026-02-15_backup.tar.gz: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match

This time, sha and sha-t are identical (comp sha sha-t). But, as you can see, the hashes in all three files are the same!? Shouldn't in 0.6.0 sha-b and sha-t be different, because of binary mode vs text mode?

Now the same with coreutils-f5fc1a597.zip:

> coreutils sha256sum -c sha
2026-02-15_backup.tar.gz: OK
> coreutils sha256sum -c sha-b
2026-02-15_backup.tar.gz: OK
> coreutils sha256sum -c sha-t
2026-02-15_backup.tar.gz: OK

(The hash code generation is the same as with 0.6.0) So this seems to be fine now. Thank you so much!

BTW: In WSL2 Ubuntu, all hashes generated by 0.6.0 from windows seem to match correctly. So the behavior of the patched coreutils.exe seems to match Ubuntu's GNU version.

BTW2: My other tests (different line endings, printf "1\r\n" being the problematic one) seem to match now, too. But you have to generate the hash files with the patched version of coreutils.exe, old hash files were calculated differently.

@RenjiSann

Copy link
Copy Markdown
Collaborator Author

Just to let you know, I didn't have time to work on this in the last days, and probably won't for another few weeks, so if someone wants to carry on, please feel free to do so :)

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/misc/usage_vs_getopt (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/csplit/csplit-heap is now passing!

Comment on lines +686 to +690
let reading_mode = if cfg!(not(unix)) {
ReadingMode::Binary
} else {
ReadingMode::Text
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I came across this issue today. Shouldn't this use the binary mode unconditionally, because the other side (in compute.rs) uses binary mode unconditionally as well?

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.

FAILED checksums using sha256sum in windows 11

6 participants