-
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
guarantee that length will never exceed isize::MAX #77
base: master
Are you sure you want to change the base?
Conversation
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.
I'm putting this up as a discussion point for fixing #69, but I definitely could've missed some details, and I haven't thought about the right way to test it yet. |
Update: As of rust-lang/rust#53784, |
OK this looks good, but please add some tests, with cases covering:
Let me know if any of this isn't clear. I imagine you will have to disable the test via |
The test can look like the one in #74, but with the parameters I mentioned here to test edge cases. |
The Ext4 filesystem on my Linux machine doesn't support files larger than 16 TB. I think you'd have to be on Btrfs or similar that to create a sparse file big enough. Also, even when using a small file with a large length (which does work for me with lengths as large as Would you be ok with only testing the failure cases here, and making sure they're returning the error they're supposed to? |
Looking closely at the table there, I think I would change some of the cases:
|
I think there were two separate issues with the previous version:
The main issue, which we've been discussing in what happens if we exceed isize::MAX on 32-bit platforms? #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."
The previous version was subtracting
self.offset
from the filelength 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.