Guard some invalid node for proof decoding. (#12417)

* Guard some invalid node for proof decoding.

* only forbid bitmap with no children.

* change format

* scale error.

* small test

Co-authored-by: parity-processbot <>
This commit is contained in:
cheme
2022-11-05 23:26:12 +01:00
committed by GitHub
parent e66339d667
commit d5677cde48
2 changed files with 18 additions and 2 deletions
+11
View File
@@ -986,4 +986,15 @@ mod tests {
assert_eq!(first_storage_root, second_storage_root);
}
#[test]
fn node_with_no_children_fail_decoding() {
let branch = NodeCodec::<Blake2Hasher>::branch_node_nibbled(
b"some_partial".iter().copied(),
24,
vec![None; 16].into_iter(),
Some(trie_db::node::Value::Inline(b"value"[..].into())),
);
assert!(NodeCodec::<Blake2Hasher>::decode(branch.as_slice()).is_err());
}
}
+7 -2
View File
@@ -304,8 +304,13 @@ const BITMAP_LENGTH: usize = 2;
pub(crate) struct Bitmap(u16);
impl Bitmap {
pub fn decode(mut data: &[u8]) -> Result<Self, codec::Error> {
Ok(Bitmap(u16::decode(&mut data)?))
pub fn decode(data: &[u8]) -> Result<Self, codec::Error> {
let value = u16::decode(&mut &data[..])?;
if value == 0 {
Err("Bitmap without a child.".into())
} else {
Ok(Bitmap(value))
}
}
pub fn value_at(&self, i: usize) -> bool {