File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -468,6 +468,8 @@ impl File {
468468 /// # Errors
469469 ///
470470 /// This function will return an error if the file is not opened for writing.
471+ /// Also, std::io::ErrorKind::InvalidInput will be returned if the desired
472+ /// length would cause an overflow due to the implementation specifics.
471473 ///
472474 /// # Examples
473475 ///
Original file line number Diff line number Diff line change @@ -557,9 +557,15 @@ impl File {
557557 return crate :: sys:: android:: ftruncate64 ( self . 0 . raw ( ) , size) ;
558558
559559 #[ cfg( not( target_os = "android" ) ) ]
560- return cvt_r ( || unsafe {
561- ftruncate64 ( self . 0 . raw ( ) , size as off64_t )
562- } ) . map ( |_| ( ) ) ;
560+ {
561+ use crate :: convert:: TryInto ;
562+ let size: off64_t = size
563+ . try_into ( )
564+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidInput , e) ) ?;
565+ cvt_r ( || unsafe {
566+ ftruncate64 ( self . 0 . raw ( ) , size)
567+ } ) . map ( |_| ( ) )
568+ }
563569 }
564570
565571 pub fn read ( & self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
You can’t perform that action at this time.
0 commit comments