Bug 14226 - Busybox md5sum fails to support backslashes in filenames
Summary: Busybox md5sum fails to support backslashes in filenames
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.33.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-23 12:54 UTC by Nils Rennebarth
Modified: 2023-01-11 17:02 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nils Rennebarth 2021-09-23 12:54:20 UTC
GNU coreutils md5sum since 2016 has a feature to make its output unambiguous even in the presence of linefeeds in filenames: It prints the filename with linefeeds escaped as \n. Of course that means is has to escape backslashes in filenames as
well. To mark a line as containing an escaped filename, it then adds a '\' at the start.

The busybox md5sum does not support this feature, and when run in check mode on a file generated by GNU coreutils md5sum, it will mark the corresponding file as 'FAILED'.

I checked the current sources and indeed, a line with an initial backslash is not handled differently. I only reviewed the code that implements -c, for full compatibility with GNU coreutils, generating md5sums will have to be adapted as well.

I might provide a patch if requested, currently I am working around this limitiation. Unfortunately, systemd decided to introduce filenames containing backslashes (sigh).
Comment 1 tlaurion 2023-01-11 17:02:45 UTC
The same behavior applies to sha256sum -c

For example (taken out of https://github.com/osresearch/heads/pull/1262#issuecomment-1377744973)

cd /boot
mkdir "$(echo -e 'hidden dir\b\b\b\b\b\b\b\b\b\bshowed dir')"
cd *hidden*
touch "$(echo -e 'file with newline\ncharacter')"
touch "file with textual new\nline"
find ./ -type f ! -path './kexec*' -print0 | xargs -0 sha256sum > /tmp/test
sha256sum -c /tmp/test | grep -v 'OK' 
sha256sum: can't open './showed dir/file with newline': No such file or directory
./showed dir/file with newline: FAILED
sha256sum: WARNING: 2 of 340 computed checksums did NOT match

cat /tmp/test
(exerpt)
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  ./showed dir/file with textual new\nline
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  ./showed dir/file with newline
character

cat /tmp/test | grep show
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  ./showed dir/file with textual new\nline
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855  ./showed dir/file with newline

ls 
(exerpt)
hidden dir??????????showed dir

/boot # cd *hidden*
/boot/showed dir # ls
file with newline?character   file with textual new\nline

----
This impacts more than mda5/sha256: this extends to ls and other busybox applets