File tree 2 files changed +29
-1
lines changed 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -395,7 +395,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
395
395
// Isolation check is done via `FileDescriptor` trait.
396
396
397
397
let seek_from = if whence == this. eval_libc_i32 ( "SEEK_SET" ) {
398
- SeekFrom :: Start ( u64:: try_from ( offset) . unwrap ( ) )
398
+ if offset < 0 {
399
+ // Negative offsets return `EINVAL`.
400
+ let einval = this. eval_libc ( "EINVAL" ) ;
401
+ this. set_last_error ( einval) ?;
402
+ return Ok ( Scalar :: from_i64 ( -1 ) ) ;
403
+ } else {
404
+ SeekFrom :: Start ( u64:: try_from ( offset) . unwrap ( ) )
405
+ }
399
406
} else if whence == this. eval_libc_i32 ( "SEEK_CUR" ) {
400
407
SeekFrom :: Current ( i64:: try_from ( offset) . unwrap ( ) )
401
408
} else if whence == this. eval_libc_i32 ( "SEEK_END" ) {
Original file line number Diff line number Diff line change
1
+ //@ignore-target-windows: File handling is not implemented yet
2
+ //@compile-flags: -Zmiri-disable-isolation
3
+
4
+ use std:: fs:: remove_file;
5
+ use std:: io:: { ErrorKind , Seek } ;
6
+
7
+ #[ path = "../../utils/mod.rs" ]
8
+ mod utils;
9
+
10
+ fn main ( ) {
11
+ let path = utils:: prepare ( "miri_test_fs_seek_i64_max_plus_1.txt" ) ;
12
+
13
+ let mut f = std:: fs:: File :: create ( & path) . unwrap ( ) ;
14
+ let error = f. seek ( std:: io:: SeekFrom :: Start ( i64:: MAX as u64 + 1 ) ) . unwrap_err ( ) ;
15
+
16
+ // It should be error due to negative offset.
17
+ assert_eq ! ( error. kind( ) , ErrorKind :: InvalidInput ) ;
18
+
19
+ // Cleanup
20
+ remove_file ( & path) . unwrap ( ) ;
21
+ }
You can’t perform that action at this time.
0 commit comments