diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-08 16:33:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-08 16:33:37 +0200 |
| commit | 76938abba13de41dd9da498226d6d549a29a3e47 (patch) | |
| tree | d6cfffd61f4816cb8856397c68a77d1e9d23a782 /src/libstd/sys | |
| parent | 8fe2d9c4e9693c5988bcebe81c9d1e046c9e791a (diff) | |
| parent | 3adbf63b119d26edf1997e974d0727791d6f4060 (diff) | |
| download | rust-76938abba13de41dd9da498226d6d549a29a3e47.tar.gz rust-76938abba13de41dd9da498226d6d549a29a3e47.zip | |
Rollup merge of #63332 - marmistrz:truncate, r=alexcrichton
Add an overflow check in truncate implementation for Unix. Closes #63326. cc @alexcrichton
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 822feacea62..3b1eb86b84f 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -557,9 +557,15 @@ impl File { return crate::sys::android::ftruncate64(self.0.raw(), size); #[cfg(not(target_os = "android"))] - return cvt_r(|| unsafe { - ftruncate64(self.0.raw(), size as off64_t) - }).map(|_| ()); + { + use crate::convert::TryInto; + let size: off64_t = size + .try_into() + .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?; + cvt_r(|| unsafe { + ftruncate64(self.0.raw(), size) + }).map(|_| ()) + } } pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> { |
