servo / servo/rust-url

Fail fast(er) for IDNA to_ascii() when given domain is too long

Open
#595 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.6k
Forks
406
PR merge metrics
No merged PRs in 30d

Description

Currently IDNA to_ascii() conversion follows what's specified in https://www.unicode.org/reports/tr46/#ToASCII . However, this takes a really long time (up to 600 ms on my tests depending on the domain) to first convert and then validate length of too long domain names. Is there a reason not to bail out fast if domain name (in any coding) is over 253 Rust chars?

See code below:

https://github.com/servo/rust-url/blob/28314752bf138a87bd8151f610d385629dec5710/idna/src/uts46.rs#L423-L464

For example my fuzzing found a domain name which is 221115 bytes long and it takes 551 ms to run to_ascii() on my machine. 539 ms is spent in idna::uts46::processing(), where 173 ms in idna::uts46::validate() and 157 ms in allocating strings. After all that tedious processing and validation is done, lengths are checked and all the effort is lost because lengths are obviously too long.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in idna/src/uts46.rs at the processing and validation code around lines 423-464. Reproduce the reported case with a very long domain passed to to_ascii(), then verify that length rejection happens earlier, preserves the specified behavior, and avoids the reported processing and allocation cost.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.