File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -92,12 +92,20 @@ impl Config {
9292 . find ( |c : char | !c. is_ascii_digit ( ) )
9393 . unwrap_or ( duration_str. len ( ) ) ;
9494 let numeric_part = & duration_str[ ..numeric_end] ;
95+ let unit_suffix = & duration_str[ numeric_end..] ;
9596
9697 // Use u128 for robust overflow detection without precision loss
9798 if let Ok ( num) = numeric_part. parse :: < u128 > ( ) {
98- // Cap at u64::MAX to prevent overflow in any duration conversion
99- const MAX_SAFE_DURATION_NUM : u128 = u64:: MAX as u128 ;
100- if num > MAX_SAFE_DURATION_NUM {
99+ // Check if value will overflow when converted to seconds based on unit
100+ // Days are the largest common unit: 1 day = 86400 seconds
101+ let max_safe_value = match unit_suffix {
102+ "d" => u64:: MAX / 86400 , // days to seconds
103+ "h" => u64:: MAX / 3600 , // hours to seconds
104+ "m" => u64:: MAX / 60 , // minutes to seconds
105+ _ => u64:: MAX , // seconds or unknown unit
106+ } ;
107+
108+ if num > max_safe_value as u128 {
101109 Duration :: from_secs ( libc:: time_t:: MAX as u64 )
102110 } else {
103111 parse_time:: from_str ( duration_str, true )
You can’t perform that action at this time.
0 commit comments