alloy-rs / alloy-rs/alloy

[Bug] Blob type being stack allocated leads to easy stack overflows

Aperta
#2,772 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Rust
Stelle
1.3k
Fork
668
Merge medio
2g 1h
PR unite (30g)
29

Descrizione

### Component

consensus, eips, genesis

### What version of Alloy are you on?

1.0.24

### Operating System

None

### Describe the bug

I noticed some stack overflows with some tests I had written. The culprit is from this type in alloy-eips
```
/// A Blob serialized as 0x-prefixed hex string
pub type Blob = FixedBytes;
```
With `BYTES_PER_BLOB = 131_072` and FixedBytes being stack allocated it seems like alot to put on the stack and can easily overflow it in some situations especially if it ends up getting cloned a couple times. This simple test below will stack overflow on Arch and MacOs ive tested(in debug mode)

```
use alloy_rpc_types_engine::BlobsBundleV2;
use ssz::Encode as _;

#[test]
fn test() {
let blobs_bundle = BlobsBundleV2 {
commitments: vec![Default::default()],
proofs: vec![Default::default()],
blobs: vec![Default::default()],
};

let bytes = blobs_bundle.as_ssz_bytes();
// following line will stack overflow
let blob: BlobsBundleV2 = ssz::Decode::from_ssz_bytes(&bytes).unwrap();
}
```

Maybe we can Box<> this type to avoid these overflows?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.