mathiasbynens / mathiasbynens/punycode.js
Overflow check in encoder differs from RFC3492?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.7k
- Forks
- 170
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I find that the JS implementation of the `toASCII()` encoder here closely resembles the C sample implementation in the RFC3492 specification, except the following:
In https://github.com/bestiejs/punycode.js/blob/702cc2daf10a5b97454666069e146d04745af728/punycode.js#L409,
``` javascript
if (currentValue < n && ++delta > maxInt) {
error('overflow');
}
```
In https://tools.ietf.org/html/rfc3492#page-27,
``` c
if (input[j] < n /* || basic(input[j]) */ ) {
if (++delta == 0) return punycode_overflow;
}
```
In particular, the JS version is checking `++delta` against whether it's larger than `maxInt`, whereas the C version is checking against whether it's equal to `0`. Is this intended, or have I missed anything when reading your code? Any clues?
Thanks!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at punycode.js line 409 and compare the JavaScript overflow condition with the C sample on RFC 3492 page 27. Determine whether the differing checks are intentional and verify the encoder’s behavior for values near the overflow boundary; done means the discrepancy is resolved with a clear explanation or correction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100