Fix an error in how cksum parses checksum files#11553
Fix an error in how cksum parses checksum files#11553frenchua wants to merge 1 commit intouutils:mainfrom
Conversation
When cksum (or sha256sum, etc...) attempts to parse chekcusm files in
the "tagged output format" and it encounters the string "((", it
crashes due to an error in how it parses the checksum file. GNU
coreutils, by contrast, correctly recognizes this string as a syntax
error and ignores the line.
|
GNU testsuite comparison: |
|
could you please add a test to make sure we don't regress in the future? |
|
Ignore (most) of what I've written above. I've read through the code more and here's whats causing the program to panic when passed syntactically incorrect checksum files. A good formatted checksum line is supposed to look something like this: If the algorithm at the beginning is missing, you have a line like the following: The parser works by looking for the first This fix causes I will write up some unit tests in the |
Both is good :) |
EDIT: After investigating more, the parsing issues are actually different that what I am describing here: See #11553 (comment) for an actual explanation on why cksum is panicking.
When cksum (or sha256sum, etc...) is called with the
-coption, and it attempts to parse cheksum files in the "tagged output format" and it encounters the string "((", it crashes due to an error in how it parses the checksum file. GNU coreutils, by contrast, correctly recognizes this line as a syntax error and ignores the line.This is due to the following two lines of code in the
parse_algo_basedfunction invalidate.rs:If the checksum file contains two consecutive left parentheses, then
par_idxis equal to zero and sorest[par_idx - 1]evaluates torest[-1]which causes the program to crash.I have added a check to make sure that
par_idxis greater than zero because, In my view, the string '((' appearing in a checksum file should be considered a syntax error and the line ignored, just as it does in the GNU cksum/sha256sum program).