BurntSushi / rust-csv

A CSV parser for Rust, with Serde support.
The Unlicense
1.72k stars 219 forks source link

Program crashes caused by inappropriate parameter sizes. #329

Closed xizheyin closed 1 year ago

xizheyin commented 1 year ago

What version of the csv crate are you using?

csv = "=1.2.2"

Briefly describe the question, bug or feature request.

Hi, csv::ByteRecord::with_capacity may panic at library/alloc/src/raw_vec.rs:518:5, or abort without error message. Perhaps it is necessary to improve the documentation to limit the size of the parameters.

Include a complete program demonstrating a problem.

fn main() {
    let mut _local1 = csv::ByteRecord::with_capacity(57855, 7205759536936779852);
}
fn main() {
    let mut _local1 = csv::ByteRecord::with_capacity(7237132204829410405, 6877548540205475283);
}

What is the observed behavior of the code above?

thread 'main' panicked at 'capacity overflow', library/alloc/src/raw_vec.rs:518:5
memory allocation of 7237132204829410405 bytes failed
Aborted
BurntSushi commented 1 year ago

Improvements to the docs are welcome, but this is just an allocation error, as the message indicates. There is no static limit that makes sense here. If you're going to try to specify a capacity that is more than available memory, then this is just what happens. It fails for the same reason Vec::with_capacity can fail.