Skip to content

Commit 4e08a0c

Browse files
committed
fix: enforce max bitfield size on decode
Honestly, we probably _don't_ need this in the FVM because: 1. Malicious inputs will burn gas for compute and won't be able to OOM the node. 2. Large bitfields will fail to serialize to state anyways. However, I'd like relaxing this check to be an explicit step. Fixes C1.
1 parent b3ae786 commit 4e08a0c

File tree

1 file changed

+6
-0
lines changed
  • ipld/bitfield/src/rleplus

1 file changed

+6
-0
lines changed

ipld/bitfield/src/rleplus/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ impl<'de> Deserialize<'de> for BitField {
105105
D: Deserializer<'de>,
106106
{
107107
let bytes: Cow<'de, [u8]> = serde_bytes::deserialize(deserializer)?;
108+
if bytes.len() > MAX_ENCODED_SIZE {
109+
return Err(serde::de::Error::custom(format!(
110+
"encoded bitfield was too large {}",
111+
bytes.len()
112+
)));
113+
}
108114
Self::from_bytes(&bytes).map_err(serde::de::Error::custom)
109115
}
110116
}

0 commit comments

Comments
 (0)