@@ -219,9 +219,19 @@ fn parse_count<T: FromStr<Err = ParseIntError> + FromStrRadix>(
219219 count : & str ,
220220) -> Result < T , Box < dyn std:: error:: Error > > {
221221 if count. starts_with ( "0x" ) || count. starts_with ( "0X" ) {
222- T :: from_str_radix ( & count[ 2 ..] , 16 ) . map_err ( |e| Box :: new ( e) as Box < dyn std:: error:: Error > )
222+ let hex_part = & count[ 2 ..] ;
223+ // Reject if hex part contains a sign
224+ if hex_part. starts_with ( '+' ) || hex_part. starts_with ( '-' ) {
225+ return Err ( "invalid hexadecimal number" . into ( ) ) ;
226+ }
227+ T :: from_str_radix ( hex_part, 16 ) . map_err ( |e| Box :: new ( e) as Box < dyn std:: error:: Error > )
223228 } else if count. starts_with ( '0' ) && count. len ( ) > 1 {
224- T :: from_str_radix ( & count[ 1 ..] , 8 ) . map_err ( |e| Box :: new ( e) as Box < dyn std:: error:: Error > )
229+ let oct_part = & count[ 1 ..] ;
230+ // Reject if octal part contains a sign
231+ if oct_part. starts_with ( '+' ) || oct_part. starts_with ( '-' ) {
232+ return Err ( "invalid octal number" . into ( ) ) ;
233+ }
234+ T :: from_str_radix ( oct_part, 8 ) . map_err ( |e| Box :: new ( e) as Box < dyn std:: error:: Error > )
225235 } else {
226236 count
227237 . parse :: < T > ( )
@@ -279,6 +289,11 @@ fn parse_offset(offset: &str) -> Result<u64, ParseIntError> {
279289 offset
280290 } ;
281291
292+ // Reject if offset contains a sign (offsets should be unsigned)
293+ if offset. starts_with ( '+' ) || offset. starts_with ( '-' ) {
294+ return Err ( "invalid offset" . parse :: < u64 > ( ) . unwrap_err ( ) ) ;
295+ }
296+
282297 let parsed_offset = u64:: from_str_radix ( offset, base) ?;
283298
284299 Ok ( parsed_offset * multiplier)
0 commit comments