-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
b3sum can't read hashes from file with non-unix endings #222
Comments
I'm not very familiar with PS, but I can repro this bug on my Windows box. It looks like it's not (only) a line endings issue, but actually a Unicode encoding issue, UTF-8 vs UTF-16. Here's how you can see it: # I've prepared a "test" directory with two files, "a" and "b"
PS C:\Users\oconn\tmp> b3sum test\*
5d3b41143cf73b55ecf4d90f2ce0bf1d3f8e4b305d45d9f9361a746eb09040f0 test/a
5d3b41143cf73b55ecf4d90f2ce0bf1d3f8e4b305d45d9f9361a746eb09040f0 test/b
# We can see that b3sum's output is UTF-8, using Python.
PS C:\Users\oconn\tmp> python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.run("b3sum test\*", shell=True, stdout=subprocess.PIPE).stdout
b'5d3b41143cf73b55ecf4d90f2ce0bf1d3f8e4b305d45d9f9361a746eb09040f0 test/a\n5d3b41143cf73b55ecf4d90f2ce0bf1d3f8e4b305d45d9f9361a746eb09040f0 test/b\n'
>>> _.decode("utf-8")
'5d3b41143cf73b55ecf4d90f2ce0bf1d3f8e4b305d45d9f9361a746eb09040f0 test/a\n5d3b41143cf73b55ecf4d90f2ce0bf1d3f8e4b305d45d9f9361a746eb09040f0 test/b\n'
# However, that's not what we get if we redirect the output in PowerShell.
# It looks like PowerShell reencodes the output as UTF-16.
PS C:\Users\oconn\tmp> b3sum test\* > out.txt
PS C:\Users\oconn\tmp> python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> open("out.txt", "rb").read()
b'\xff\xfe5\x00d\x003\x00b\x004\x001\x001\x004\x003\x00c\x00f\x007\x003\x00b\x005\x005\x00e\x00c\x00f\x004\x00d\x009\x000\x00f\x002\x00c\x00e\x000\x00b\x00f\x001\x00d\x003\x00f\x008\x00e\x004\x00b\x003\x000\x005\x00d\x004\x005\x00d\x009\x00f\x009\x003\x006\x001\x00a\x007\x004\x006\x00e\x00b\x000\x009\x000\x004\x000\x00f\x000\x00 \x00 \x00t\x00e\x00s\x00t\x00/\x00a\x00\r\x00\n\x005\x00d\x003\x00b\x004\x001\x001\x004\x003\x00c\x00f\x007\x003\x00b\x005\x005\x00e\x00c\x00f\x004\x00d\x009\x000\x00f\x002\x00c\x00e\x000\x00b\x00f\x001\x00d\x003\x00f\x008\x00e\x004\x00b\x003\x000\x005\x00d\x004\x005\x00d\x009\x00f\x009\x003\x006\x001\x00a\x007\x004\x006\x00e\x00b\x000\x009\x000\x004\x000\x00f\x000\x00 \x00 \x00t\x00e\x00s\x00t\x00/\x00b\x00\r\x00\n\x00'
>>> _.decode("utf-16")
'5d3b41143cf73b55ecf4d90f2ce0bf1d3f8e4b305d45d9f9361a746eb09040f0 test/a\r\n5d3b41143cf73b55ecf4d90f2ce0bf1d3f8e4b305d45d9f9361a746eb09040f0 test/b\r\n' We can see at the end there that there are Windows-style newlines, and I expect those would cause a problem in b3sum. But we never get to that problem, because we try to decode the checkfile as UTF-8 and fail immediately. I'm not sure what the best workaround is for this. Is there a way to tell PowerShell to redirect raw bytes? |
Which version of powershell you're using? I'm running the latest PowerShell 7.2.1 and seems it outputs UTF-8 correctly:
But cmd with cmd it's outputting correct file:
Just adding ability to read any file endings. Because it's possible to create txt file from notepad, paste hashes here, and it will still not work |
This is a reasonable idea, but I want to clarify that it's backwards-incompatible with what |
On Debian 12, I find that GNU coreutils (md5sum/sha*sum/b2sum), do escape CR to "\r". I found a relevant commit here, with some reasoning about it, also involving Windows. Anyway, it seemed relevant to mention here. |
I would like to cross reference: (1) blake3 / incompatibilities with cli (original) b3sum implementation - Total Commander |
I'm using powershell
Output for each file is:
: FAILED (Syntax error in file name, folder name or volume label. (Os error 123))
But after running
busybox dos2unix hash.txt
it works correctlySimilar #108
The text was updated successfully, but these errors were encountered: