mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
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:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user