rust-lang / rust-lang/rust

Program crash in vector initialization: crash in extend_with

Open
#146,033 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-array C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

    let mut drv = Vec::<[[f64; 512]; 512]>::new();
    drv.resize(4, [[0.0; 512]; 512]);

Only in Debug.

I expected to see this happen:

Not crash. I'd be ok with an assert or something.

Instead, this happened:

thread 'main' has overflowed its stack
fatal runtime error: stack overflow, aborting
zsh: IOT instruction (core dumped)  cargo run
Meta

rustc --version --verbose:

rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: x86_64-unknown-linux-gnu
release: 1.89.0
LLVM version: 20.1.7

Playground link
(updated, it was the wrong version)

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=440dea0d584ba2f6c398567db095a023

Using vec![] instead of the Vec::new() and resize() cause the same error. (see Playground)

Happens with nightly

rustc 1.91.0-nightly (fe5536432 2025-08-29) (from rustc 1.91.0-nightly (809200ec9 2025-08-24))
Backtrace

No more info with RUST_BACKTRACE=1

With GDB

Program received signal SIGSEGV, Segmentation fault.
0x0000555555559d51 in alloc::vec::Vec<[[f64; 512]; 512], alloc::alloc::Global>::extend_with<[[f64; 512]; 512], alloc::alloc::Global> (
    self=0x0, n=0, value=...)
    at /var/home/hub/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:3191
3191	    fn extend_with(&mut self, n: usize, value: T) {
(gdb) where
#0  0x0000555555559d51 in alloc::vec::Vec<[[f64; 512]; 512], alloc::alloc::Global>::extend_with<[[f64; 512]; 512], alloc::alloc::Global> (
    self=0x0, n=0, value=...)
    at /var/home/hub/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:3191
#1  0x000055555555a10d in alloc::vec::Vec<[[f64; 512]; 512], alloc::alloc::Global>::resize<[[f64; 512]; 512], alloc::alloc::Global> (
    self=0x7fffffdfcca8, new_len=4, value=<error reading variable: value requires 2097152 bytes, which is more than max-value-size>)
    at /var/home/hub/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:3071
#2  0x000055555555a336 in test_rust::main () at src/main.rs:10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Playground example, then inspect alloc/src/vec/mod.rs around Vec::resize and extend_with. Determine why the large array value causes a debug stack overflow and define the expected failure behavior; add regression coverage and verify the example no longer aborts unexpectedly.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.