Accept only decimal digits in file names inside snapshot (#21213)

This also should make snapshot validation a bit faster.
This commit is contained in:
Ivan Mironov
2021-11-15 22:02:15 +05:00
committed by GitHub
parent a043b19988
commit 9b1bf98aa2

View File

@ -346,7 +346,7 @@ fn all_digits(v: &str) -> bool {
return false; return false;
} }
for x in v.chars() { for x in v.chars() {
if !x.is_numeric() { if !x.is_digit(10) {
return false; return false;
} }
} }
@ -357,7 +357,7 @@ fn like_storage(v: &str) -> bool {
let mut periods = 0; let mut periods = 0;
let mut saw_numbers = false; let mut saw_numbers = false;
for x in v.chars() { for x in v.chars() {
if !x.is_numeric() { if !x.is_digit(10) {
if x == '.' { if x == '.' {
if periods > 0 || !saw_numbers { if periods > 0 || !saw_numbers {
return false; return false;
@ -521,6 +521,10 @@ mod tests {
&["snapshots", "0x"], &["snapshots", "0x"],
tar::EntryType::Directory tar::EntryType::Directory
)); ));
assert!(!is_valid_snapshot_archive_entry(
&["snapshots", ""],
tar::EntryType::Directory
));
assert!(!is_valid_snapshot_archive_entry( assert!(!is_valid_snapshot_archive_entry(
&["snapshots", "0", "aa"], &["snapshots", "0", "aa"],
tar::EntryType::Regular tar::EntryType::Regular
@ -567,6 +571,10 @@ mod tests {
&["accounts", "232323"], &["accounts", "232323"],
tar::EntryType::Regular tar::EntryType::Regular
)); ));
assert!(!is_valid_snapshot_archive_entry(
&["accounts", "৬.¾"],
tar::EntryType::Regular
));
} }
#[test] #[test]