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
+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 {