File tree 4 files changed +10
-5
lines changed
4 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ use alloc::{string::String, vec::Vec};
17
17
use core:: char;
18
18
use core:: fmt:: Write ;
19
19
use core:: marker:: PhantomData ;
20
- use core:: u32;
21
20
22
21
// Bootstring parameters for Punycode
23
22
const BASE : u32 = 36 ;
@@ -215,7 +214,7 @@ impl Decoder {
215
214
if C :: EXTERNAL_CALLER && ( digit > ( u32:: MAX - i) / weight) {
216
215
return Err ( ( ) ) ; // Overflow
217
216
}
218
- i += digit * weight;
217
+ i = i . checked_add ( digit * weight) . ok_or ( ( ) ) ? ;
219
218
let t = if k <= bias {
220
219
T_MIN
221
220
} else if k >= bias + T_MAX {
Original file line number Diff line number Diff line change @@ -40,6 +40,12 @@ fn test_punycode_prefix_without_length_check() {
40
40
assert ! ( config. to_ascii( "xn--.example.org" ) . is_err( ) ) ;
41
41
}
42
42
43
+ #[ test]
44
+ fn test_punycode_invalid_encoding ( ) {
45
+ let config = idna:: Config :: default ( ) ;
46
+ assert ! ( config. to_ascii( "xn--55555577" ) . is_err( ) ) ;
47
+ }
48
+
43
49
// http://www.unicode.org/reports/tr46/#Table_Example_Processing
44
50
#[ test]
45
51
fn test_examples ( ) {
Original file line number Diff line number Diff line change @@ -309,7 +309,7 @@ fn parse_ipv4addr(input: &str) -> ParseResult<Ipv4Addr> {
309
309
}
310
310
let mut ipv4 = numbers. pop ( ) . expect ( "a non-empty list of numbers" ) ;
311
311
// Equivalent to: ipv4 >= 256 ** (4 − numbers.len())
312
- if ipv4 > u32:: max_value ( ) >> ( 8 * numbers. len ( ) as u32 ) {
312
+ if ipv4 > u32:: MAX >> ( 8 * numbers. len ( ) as u32 ) {
313
313
return Err ( ParseError :: InvalidIpv4Address ) ;
314
314
}
315
315
if numbers. iter ( ) . any ( |x| * x > 255 ) {
Original file line number Diff line number Diff line change @@ -1109,7 +1109,7 @@ impl<'a> Parser<'a> {
1109
1109
while let ( Some ( c) , remaining) = input. split_first ( ) {
1110
1110
if let Some ( digit) = c. to_digit ( 10 ) {
1111
1111
port = port * 10 + digit;
1112
- if port > :: std :: u16:: MAX as u32 {
1112
+ if port > u16:: MAX as u32 {
1113
1113
return Err ( ParseError :: InvalidPort ) ;
1114
1114
}
1115
1115
has_any_digit = true ;
@@ -1590,7 +1590,7 @@ pub fn ascii_alpha(ch: char) -> bool {
1590
1590
1591
1591
#[ inline]
1592
1592
pub fn to_u32 ( i : usize ) -> ParseResult < u32 > {
1593
- if i <= :: std :: u32:: MAX as usize {
1593
+ if i <= u32:: MAX as usize {
1594
1594
Ok ( i as u32 )
1595
1595
} else {
1596
1596
Err ( ParseError :: Overflow )
You can’t perform that action at this time.
0 commit comments