Skip to content

Commit

Permalink
fix overflow when processing punycode encoded URLs like xn--55555577
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jun 16, 2024
1 parent 8db8034 commit d40d472
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion idna/src/punycode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl Decoder {
if C::EXTERNAL_CALLER && (digit > (u32::MAX - i) / weight) {
return Err(()); // Overflow
}
i += digit * weight;
i = i.checked_add(digit * weight).ok_or(())?;
let t = if k <= bias {
T_MIN
} else if k >= bias + T_MAX {
Expand Down
2 changes: 1 addition & 1 deletion idna/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn test_punycode_prefix_without_length_check() {
#[test]
fn test_punycode_invalid_encoding() {
let config = idna::Config::default();
assert_eq!(config.to_ascii("xn--55555577").unwrap_err().to_string(), "Errors { punycode }");
assert!(config.to_ascii("xn--55555577").is_err());
}

// http://www.unicode.org/reports/tr46/#Table_Example_Processing
Expand Down

0 comments on commit d40d472

Please sign in to comment.