-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-llvmWorking group: LLVM backend code generationWorking group: LLVM backend code generation
Description
I tried this code:
use std::thread;
const KILO: usize = 1024;
const MEGA: usize = 1024 * KILO;
const GIGA: usize = 1024 * MEGA;
const BUFFER_SIZE: usize = 4 * GIGA;
const REQUIRED_STACK_SIZE: usize = 512 * MEGA + BUFFER_SIZE;
fn main() {
thread::Builder::new()
.stack_size(REQUIRED_STACK_SIZE)
.spawn(perform_double_free).unwrap()
.join().unwrap();
}
fn perform_double_free() {
make_noise();
let mut buffer = [0; BUFFER_SIZE];
write_to_buffer(&mut buffer, 0);
}
fn make_noise() {
vec![0].append(&mut vec![0]);
}
fn write_to_buffer(buffer: &mut [u8; BUFFER_SIZE], mut i: usize) {
i += 4096;
if i >= BUFFER_SIZE {
return;
}
write_to_buffer(buffer, i);
buffer[i] = 1;
}I expected the program to exit normally.
Instead, this happened:
free(): double free detected in tcache 2
Aborted
Meta
Tested on Linux with the following Rust versions :
rustc 1.63.0 (4b91a6ea7 2022-08-08)rustc 1.64.0-beta.3 (82bf34178 2022-08-18)rustc 1.65.0-nightly (015a824f2 2022-08-22)
Only reproducible with --release.
Can be reproduced on Windows inside a Rust Docker container.
The program may use about 5 GiB of memory and may hang the system. So be sure to have enough space and be ready to kill the process.
Backtrace
No backtrace is printed with RUST_BACKTRACE=1.
Xiretza and bczhcXiretza, kamulos, bczhc and paolobarbolini
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-llvmWorking group: LLVM backend code generationWorking group: LLVM backend code generation