safe slice operation (#5471)

This commit is contained in:
thiolliere
2020-03-31 18:41:55 +02:00
committed by GitHub
parent 2e76e2a74d
commit 1363675adb
+8
View File
@@ -92,6 +92,10 @@ impl StorageHasher for Twox64Concat {
}
impl ReversibleStorageHasher for Twox64Concat {
fn reverse(x: &[u8]) -> &[u8] {
if x.len() < 8 {
crate::debug::error!("Invalid reverse: hash length too short");
return &[]
}
&x[8..]
}
}
@@ -110,6 +114,10 @@ impl StorageHasher for Blake2_128Concat {
}
impl ReversibleStorageHasher for Blake2_128Concat {
fn reverse(x: &[u8]) -> &[u8] {
if x.len() < 16 {
crate::debug::error!("Invalid reverse: hash length too short");
return &[]
}
&x[16..]
}
}