-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
cksum: Fix GNU test cksum-c.sh after bump to 9.9
#9511
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
Conversation
b03ec78 to
5f883fc
Compare
CodSpeed Performance ReportMerging #9511 will not alter performanceComparing Summary
Footnotes
|
cd5feaa to
e522a31
Compare
|
GNU testsuite comparison: |
e522a31 to
19df883
Compare
cksum-c.sh after bump to 9.9cksum-c.sh after bump to 9.9
|
GNU testsuite comparison: |
19df883 to
3279939
Compare
|
GNU testsuite comparison: |
| line_info: &LineInfo, | ||
| len_hint: Option<usize>, | ||
| checksum: &String, | ||
| bytelen_hint: Option<usize>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use byte_len_hint because "byte" and "length" are words on their own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
| // checksum with it. | ||
| let digest_char_length_hint = match (algo_kind, algo_byte_len) { | ||
| (AlgoKind::Blake2b, Some(bytelen)) => Some(bytelen * 2), | ||
| (AlgoKind::Blake2b, Some(bytelen)) => Some(bytelen), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here (plus for consistency reasons, as one line above algo_byte_len is used).
| (AlgoKind::Blake2b, Some(bytelen)) => Some(bytelen), | |
| (AlgoKind::Blake2b, Some(byte_len)) => Some(byte_len), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
This commit differentiates Base64 strings that are known to be invalid before decoding (because their length is not a multiple of 4), from Base64 strings that are invalid at decoding (padding is invalid).
3279939 to
ba5ded0
Compare
|
GNU testsuite comparison: |
| match base64_simd::forgiving_decode_to_vec(checksum.as_bytes()) { | ||
| Ok(buffer) if checks_hint(buffer.len()) => Some(hex::encode(buffer).into()), | ||
| // The resulting length is not as expected | ||
| Ok(_) => None, | ||
| Err(_) => None, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A functional approach might be cleaner, though I'm aware it's subjective. Feel free to ignore this comment ;-)
base64_simd::forgiving_decode_to_vec(checksum.as_bytes())
.ok()
.and_then(|buffer| {
if checks_hint(buffer.len()) {
Some(hex::encode(buffer).into())
} else {
None
}
})There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with you. However, I'm changing this in the following MR #9532, so I will keep it like so on this MR and avoid a funny rebase :)
Kudos :) |
The latest GNU release added tests to
cksum-cwhich made our implementation fail.Namely, the testcase that was problematic was the following:
This command used to produce an "improperly formatted line" error, but is now required to fail at the string digest comparison.
The error here is that the digest is an invalid BASE64 string: although it is the right length, the last
+breaks the padding, so our code previously failed to decode it.This MR makes the difference between Base64 strings that are known to be invalid before decoding, which should be considered as improperly formatted lines, and those that are only recognized to be invalid after decoding, for padding issues, which are to be regarded as properly formatted compared to the obtained checksum.