File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ pub enum ParseError {
4747 BsOutOfRange ( String ) ,
4848 #[ error( "{}" , translate!( "dd-error-invalid-number" , "input" => . 0 . clone( ) ) ) ]
4949 InvalidNumber ( String ) ,
50+ #[ error( "invalid number: ‘{0}’: {1}" ) ]
51+ InvalidNumberWithErrMsg ( String , String ) ,
5052}
5153
5254/// Contains a temporary state during parsing of the arguments
@@ -243,11 +245,25 @@ impl Parser {
243245 . skip
244246 . force_bytes_if ( self . iflag . skip_bytes )
245247 . to_bytes ( ibs as u64 ) ;
248+ // GNU coreutils has a limit of i64 (intmax_t)
249+ if skip > i64:: MAX as u64 {
250+ return Err ( ParseError :: InvalidNumberWithErrMsg (
251+ format ! ( "{skip}" ) ,
252+ "Value too large for defined data type" . to_string ( ) ,
253+ ) ) ;
254+ }
246255
247256 let seek = self
248257 . seek
249258 . force_bytes_if ( self . oflag . seek_bytes )
250259 . to_bytes ( obs as u64 ) ;
260+ // GNU coreutils has a limit of i64 (intmax_t)
261+ if seek > i64:: MAX as u64 {
262+ return Err ( ParseError :: InvalidNumberWithErrMsg (
263+ format ! ( "{seek}" ) ,
264+ "Value too large for defined data type" . to_string ( ) ,
265+ ) ) ;
266+ }
251267
252268 let count = self . count . map ( |c| c. force_bytes_if ( self . iflag . count_bytes ) ) ;
253269
Original file line number Diff line number Diff line change @@ -1830,3 +1830,13 @@ fn test_oflag_direct_partial_block() {
18301830 at. remove ( input_file) ;
18311831 at. remove ( output_file) ;
18321832}
1833+
1834+ #[ test]
1835+ fn test_skip_overflow ( ) {
1836+ new_ucmd ! ( )
1837+ . args ( & [ "bs=1" , "skip=9223372036854775808" , "count=0" ] )
1838+ . fails ( )
1839+ . stderr_contains (
1840+ "dd: invalid number: ‘9223372036854775808’: Value too large for defined data type" ,
1841+ ) ;
1842+ }
You can’t perform that action at this time.
0 commit comments