Skip to content

Program crash on Reader.read_exact #19652

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
vwim opened this issue Dec 9, 2014 · 4 comments
Closed

Program crash on Reader.read_exact #19652

vwim opened this issue Dec 9, 2014 · 4 comments
Labels
A-allocators Area: Custom and system allocators

Comments

@vwim
Copy link

vwim commented Dec 9, 2014

Here's a little snippet to show the problem. Since I updated to the latest rustc I don't get a full crash report, so this is all I got.

use std::io;

fn main() {
    let mut b = io::BufReader::new(b"Hello world!");

    //let r = b.read_exact(2000000000000);  //<-- Works as expected, prints error "end of file"
    let r = b.read_exact(200000000000000);  //<-- When input way too large it causes a crash

    match r {
        Ok(_) => (),
        Err(e) => println!("{}", e)
    }
}

rustc 0.13.0-nightly (8bca470 2014-12-08 00:12:30 +0000)
binary: rustc
commit-hash: 8bca470
commit-date: 2014-12-08 00:12:30 +0000
host: x86_64-apple-darwin
release: 0.13.0-nightly

OS: Mac OS X 10.9.4

@sfackler
Copy link
Member

sfackler commented Dec 9, 2014

read_exact allocates a Vec to store the data it returns. Your OS is not willing to allocate 200 terabytes of memory, which causes the program to abort.

@vwim
Copy link
Author

vwim commented Dec 9, 2014

Your right, didn't think about that :)
Now i'm wondering, should it just crash or give some sort of error?

@sfackler
Copy link
Member

sfackler commented Dec 9, 2014

It's certainly desired to try to print something before aborting when running out of memory: #14674.

@thestinger thestinger added A-allocators Area: Custom and system allocators B-notabug labels Dec 15, 2014
@thestinger
Copy link
Contributor

This is working as intended. Printing an error instead of just aborting is covered by #14674. There's currently no better way to deal with this short of bubbling up out-of-memory errors everywhere.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-allocators Area: Custom and system allocators
Projects
None yet
Development

No branches or pull requests

3 participants