Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Uncaught exception] UnicodeError (punycode) when calling decode with arbitrary data #109

Closed
pventuzelo opened this issue Oct 3, 2021 · 0 comments

Comments

@pventuzelo
Copy link

Hey,

I just found another case making the program crash where idna.decode() raise a UnicodeError (due to punycode).

In the same way as #108, this could be problematic if users of the library are dealing with untrusted data since this issue will lead to a DoS. This should be detected and an idna.IDNAError should be triggered as detailed in the Readme Exception section.

Reproduction

import idna

idna.decode(b'A.A.0.a.a.A.0.a.A.A.0.a.A.0A.2.a.A.A.0.a.A.0.A.a.A0.a.a.A.0.a.fB.A.A.a.A.A.B.A.A.a.A.A.B.A.A.a.A.A.0.a.A.a.a.A.A.0.a.A.0.A.a.A0.a.a.A.0.a.fB.A.A.a.A.A.B.0A.A.a.A.A.B.A.A.a.A.A.a.A.A.B.A.A.a.A.0.a.B.A.A.a.A.B.A.a.A.A.5.a.A.0.a.Ba.A.B.A.A.a.A.0.a.Xn--B.A.A.A.a')

Traceback

python3 replay_crash2.py
Traceback (most recent call last):
  File "/usr/lib/python3.8/encodings/punycode.py", line 134, in decode_generalized_number
    char = ord(extended[extpos])
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/encodings/punycode.py", line 207, in decode
    res = punycode_decode(input, errors)
  File "/usr/lib/python3.8/encodings/punycode.py", line 194, in punycode_decode
    return insertion_sort(base, extended, errors)
  File "/usr/lib/python3.8/encodings/punycode.py", line 164, in insertion_sort
    newpos, delta = decode_generalized_number(extended, extpos,
  File "/usr/lib/python3.8/encodings/punycode.py", line 137, in decode_generalized_number
    raise UnicodeError("incomplete punicode string")
UnicodeError: incomplete punicode string

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "replay_crash2.py", line 3, in <module>
    idna.decode(b'A.A.0.a.a.A.0.a.A.A.0.a.A.0A.2.a.A.A.0.a.A.0.A.a.A0.a.a.A.0.a.fB.A.A.a.A.A.B.A.A.a.A.A.B.A.A.a.A.A.0.a.A.a.a.A.A.0.a.A.0.A.a.A0.a.a.A.0.a.fB.A.A.a.A.A.B.0A.A.a.A.A.B.A.A.a.A.A.a.A.A.B.A.A.a.A.0.a.B.A.A.a.A.B.A.a.A.A.5.a.A.0.a.Ba.A.B.A.A.a.A.0.a.Xn--B.A.A.A.a')
  File "/home/scop/.local/lib/python3.8/site-packages/idna/core.py", line 402, in decode
    s = ulabel(label)
  File "/home/scop/.local/lib/python3.8/site-packages/idna/core.py", line 315, in ulabel
    label = label_bytes.decode('punycode')
UnicodeError: decoding with 'punycode' codec failed (UnicodeError: incomplete punicode string)

Happy to help if you have any questions ;)

@kjd kjd closed this as completed in 4fdcc18 Oct 3, 2021
kjd added a commit that referenced this issue Oct 3, 2021
Raise IDNAError exception on invalid A-label (fixes #109)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant