mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 14:27:57 +00:00
assert trie odd nibble padding on decoding (#2218)
* Do not allow malleability in odd slice padding. * align dep
This commit is contained in:
@@ -61,12 +61,18 @@ impl<H: Hasher> trie_db::NodeCodec<H> for NodeCodec<H> {
|
||||
Ok(Node::Branch(children, value))
|
||||
}
|
||||
NodeHeader::Extension(nibble_count) => {
|
||||
if nibble_count % 2 == 1 && input[0] & 0xf0 != 0x00 {
|
||||
return Err(BadFormat);
|
||||
}
|
||||
let nibble_data = take(input, (nibble_count + 1) / 2).ok_or(BadFormat)?;
|
||||
let nibble_slice = NibbleSlice::new_offset(nibble_data, nibble_count % 2);
|
||||
let count = <Compact<u32>>::decode(input).ok_or(BadFormat)?.0 as usize;
|
||||
Ok(Node::Extension(nibble_slice, take(input, count).ok_or(BadFormat)?))
|
||||
}
|
||||
NodeHeader::Leaf(nibble_count) => {
|
||||
if nibble_count % 2 == 1 && input[0] & 0xf0 != 0x00 {
|
||||
return Err(BadFormat);
|
||||
}
|
||||
let nibble_data = take(input, (nibble_count + 1) / 2).ok_or(BadFormat)?;
|
||||
let nibble_slice = NibbleSlice::new_offset(nibble_data, nibble_count % 2);
|
||||
let count = <Compact<u32>>::decode(input).ok_or(BadFormat)?.0 as usize;
|
||||
|
||||
Reference in New Issue
Block a user