alloy-rs/core

[Bug] Deserializing json Blob results in stackoverflow

Closed this issue · 1 comments

Component

rpc

What version of Alloy are you on?

main

Operating System

macOS (Apple Silicon)

Describe the bug

the Blob alias is a very large array (131_072):

https://github.com/alloy-rs/alloy/blob/eb0d564f0105254b9fc29be6dde301d4a2b74ebc/crates/eips/src/eip4844/mod.rs#L72-L73

following code results in a SO in debug:

 let s = r#""0x...large blob""#;

        let blob = serde_json::from_str::<Blob>(s);

full blob (too large for issue): https://gist.github.com/mattsse/c2e5060d45f074d852d7a63086244917

but just using a hex string, and not json string, this succeeds:

let blob = <Blob as hex::FromHex>::from_hex(s);

parsing it as the c-kzg Blob type which is also just an array does succeed

This also fails

let blob = serde_json::from_str::<Box<Blob>>(s);

this workaround works

fn deserialize_blob<'de, D>(deserializer: D) -> Result<Box<Blob>, D::Error>
    where
        D: serde::de::Deserializer<'de>,
{
    let s = String::deserialize(deserializer)?;
    Blob::from_str(&s).map(Box::new).map_err(serde::de::Error::custom)
}

Closing this as wontfix. Per @DaniPopes research, issue occurs because tests are run with 2MB stacks, and the serde_json deserialization routine needs more stack space to deserialize a blob on the stack. Should be addressed by boxing blobs