Skip to content

Stack overflow when decoding large boxed arrays #419

@nazar-pc

Description

@nazar-pc

Example:

#![feature(new_uninit)]
use parity_scale_codec::{Decode, Encode};

#[derive(Encode, Decode)]
struct S(Box<[u8; 100 * 1024 * 1024]>);

impl Default for S {
    fn default() -> Self {
        Self(unsafe { Box::new_zeroed().assume_init() })
    }
}

fn main() {
    let s = S::default();
    let encoded = s.encode();
    println!("Encoded successfully");
    S::decode(&mut encoded.as_slice()).unwrap();
}

Output:

Encoded successfully

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
fish: Job 1, 'cargo run --example overflow' terminated by signal SIGABRT (Abort)

Likely due to rust-lang/rust#53827

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions