Filenames with newlines aren't handled properly #695
Labels
No labels
announcement
bug
build
CI
dependencies
documentation
duplicate
enhancement
experience feedback
feature request
github_actions
help wanted
install
invalid
Long-term
optimization
portability
question
target-specific
test issue
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-Cyan4973/xxHash#695
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When I use
md5sum(version 9.0 from GNU coreutils), I can properly calculate and verify hashes of files containing0x0Ain their filenames:Unfortunately, this intended behaviour cannot be replicated with
xxhsum(version 0.8.1):Filenames containing carriage returns (
0x0D) act bizarrely when quoted (finished with tab complete):as well as when unquoted:
Notice the 'bar' overlapped part of the hash in my terminal and makes it look like a file named 'bar' has a matching hash. GNU coreutils'
md5sumuses\rinstead of the raw character (excluding its-zflag).It seems that the offending character(s) are not backslash-escaped and therefore causes confusion with
xxhsumwhen parsing the list back.Including/omitting
--tagresults in the same behaviour.Tested using Arch GNU/Linux.
Hi @systwi-again, thanks for the report.
I've confirmed your issue. So far, I put terminal agnostic version of your investigation for contributors and future version of our test.
How
md5sum(digest.c) handles special characters in the filename?filename_unescape()unescapes the following characters\n(0x0a, LF)\r(0x0d, CR)\\(0x5c, back slash)It doesn't accept other
\escaped characters such as\0or\x7f.It also doesn't accept
NUL(0x00) as a part of filename.filename_unescape()https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/digest.c?id=04d735ea9637b213ef7fc327a635decbbf20152e#n547
How
md5sum(digest.c) put\at the beginning of the line?If filename contains escaped character,
digest_check()put\at the beginning of the line.https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/digest.c?id=04d735ea9637b213ef7fc327a635decbbf20152e#n1130
https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/digest.c?id=04d735ea9637b213ef7fc327a635decbbf20152e#n1165
The following functions also recognize escaped filename.
split_3(),escaped_filenamehttps://git.savannah.gnu.org/cgit/coreutils.git/tree/src/digest.c?id=04d735ea9637b213ef7fc327a635decbbf20152e#n716
print_filename(),escapehttps://git.savannah.gnu.org/cgit/coreutils.git/tree/src/digest.c?id=04d735ea9637b213ef7fc327a635decbbf20152e#n858
output_file(),needs_escapehttps://git.savannah.gnu.org/cgit/coreutils.git/tree/src/digest.c?id=04d735ea9637b213ef7fc327a635decbbf20152e#n970
I've made experimental branch for this issue - https://github.com/t-mat/xxHash/tree/issue-695
You can check it by the following commands
But I have 2 questions
(1) Should we really support
\n,\rin the filename / path?I'm really sorry. And this is 100% my personal taste.
I think we should refuse these filename / path. E.g. just display
Error: Failed to open the file.Because practically we don't gain any benefit from these filenames. I think they just spread confusion and inconvenience.
But since we've been stating and trying to mimic
md5sum, we should accept it though.(2) Should we introduce md5sum style convention to BSD style line?
Since I'm no-brainer, I put same rule to
XSUM_printLine_BSD_internal(). But I have absolutely no knowledge about it. I honestly need some help.Good question,
I've got essentially the same state of mind :
I would prefer to simplify the situation, even at the cost of forbidding these cases,
but if the goal is to mimic
md5sum, andmd5sumsupports these characters,then it would be a change of objective.
Hence I presume it's better to support them, though this is weak preference.
If the code becomes massively complex because of that, we might want to revisit that.
Same idea, it depends on
md5sum --tagsupport.My understanding is that it supports the same rules (regarding "complex" characters) as the regular
md5sumoutput format.Sure!
--tagsupportYou're right. I've checked
md5sum --tag. And your assumption is right.I also checked
xxhsum --tagin my branch. Since it behaves similar, seems okay.--zeroIt seems filename escaping has relation with
--zero. Their web (info) manual ofmd5sumhas the following note.So, should we also introduce this feature?
Personally, I'd like to leave it for now. And wait for actual application program which take a benefit from this feature.
Agreed
I've added test script to my branch.
make test-filename-escapeinvokes the test script.The test script
filename-escape.shinvokes the following commands and report there's any error or not.Hi @systwi-again, since we've merged the fix of this issue, could you check fresh
devbranch?When you'll confirm the resolution. we'd like to close this issue.
Thank you @t-mat and @Cyan4973 for looking into this issue. I sincerely apologize for the delay in replying.
The fixes in the
devbranch work perfectly under my Arch GNU/Linux install. Thanks again! :)