Skip to content

Commit

Permalink
Accept only decimal digits in file names inside snapshot (solana-labs…
Browse files Browse the repository at this point in the history
…#21213)

This also should make snapshot validation a bit faster.
  • Loading branch information
im-0 authored Nov 15, 2021
1 parent a043b19 commit 9b1bf98
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions runtime/src/hardened_unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ fn all_digits(v: &str) -> bool {
return false;
}
for x in v.chars() {
if !x.is_numeric() {
if !x.is_digit(10) {
return false;
}
}
Expand All @@ -357,7 +357,7 @@ fn like_storage(v: &str) -> bool {
let mut periods = 0;
let mut saw_numbers = false;
for x in v.chars() {
if !x.is_numeric() {
if !x.is_digit(10) {
if x == '.' {
if periods > 0 || !saw_numbers {
return false;
Expand Down Expand Up @@ -521,6 +521,10 @@ mod tests {
&["snapshots", "0x"],
tar::EntryType::Directory
));
assert!(!is_valid_snapshot_archive_entry(
&["snapshots", "①"],
tar::EntryType::Directory
));
assert!(!is_valid_snapshot_archive_entry(
&["snapshots", "0", "aa"],
tar::EntryType::Regular
Expand Down Expand Up @@ -567,6 +571,10 @@ mod tests {
&["accounts", "232323"],
tar::EntryType::Regular
));
assert!(!is_valid_snapshot_archive_entry(
&["accounts", "৬.¾"],
tar::EntryType::Regular
));
}

#[test]
Expand Down

0 comments on commit 9b1bf98

Please sign in to comment.