-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
what happens if we exceed isize::MAX on 32-bit platforms? #69
Comments
@oconnor663 can you be more specific with your concern? Do you have a specific potentially buggy line of code in mind, or perhaps a reproducible example? |
I'm worried about what happens in the case where someone on a 32-bit system memory maps a 3 GB file (that is, longer than
According to the That said, I have no idea what actually happens in this case. It could be that, even though the My instinct is that |
@oconnor663 thanks for the detail. I put together #74 to try and reproduce this scenario; we'll see whether it crashes and burns on the 32bit CI targets. If you don't mind, please take a look and check if that test accurately reflects the scenario you're concerned about. |
Early indications are that test fails with |
Hmm, maybe we should test whether a 2^31 - 2 byte mmap (just under |
Some more discussion here: https://www.reddit.com/r/rust/comments/9ghwuv/hey_rustaceans_got_an_easy_question_ask_here/e6fx4h2/ I get the feeling that these are problems we don't want to touch with a 10 foot pole :) |
I think there were two separate issues with the previous version: 1. The main issue, which we've been discussing in danburkert#69, is that it's unsound to construct a slice larger that isize::MAX. That said, it might be impossible to trigger this behavior on some 32-bit systems. The comment linked to in raw_vec.rs says it requires "a platform which can use all 4GB in user-space. e.g. PAE or x32." 2. The previous version was subtracting `self.offset` from the file length without checking for negative overflow. Very large offsets could have turned into an accidentally valid section of the file, in release mode when the overflow didn't panic.
Update: As of rust-lang/rust#53784, |
Note that stdlib debug asserts don’t ever run in official compiler builds. Only for like the rust-lang test suite. |
@oconnor663 The only places that use |
Woops, sorry I completely missed the link between |
The
ptr::offset
function, which underlies safe slice indexing, says in its docs:Since the
map
function isunsafe
, it's arguably fine for it to expose possible UB in this way. But I think most people reading the docs won't have any idea that this is a requirement.Maybe it would be better for(Edit: Probably just return an error if we try to mmap something larger thanDeref
to panic rather than to return a slice that's "unsoundly large"?isize::MAX
?)The text was updated successfully, but these errors were encountered: