[issue30566] punycode codec raises IndexError in decode_generalized_number()

2017-09-13 Thread Vikram Hegde

Vikram Hegde added the comment:

Could someone please review my PR. It has been in the pending state for over 
three months.

--
nosy: +vikhegde

___
Python tracker 
<https://bugs.python.org/issue30566>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30566] punycode codec raises IndexError in decode_generalized_number()

2017-06-04 Thread Vikram Hegde

New submission from Vikram Hegde:

Here is the relevant code snippet from  decode_generalized_number() in 
punycode.py

try:
char = ord(extended[extpos])
except IndexError:
if errors == "strict":
raise UnicodeError("incomplete punicode string")
return extpos + 1, None
extpos += 1
if 0x41 <= char <= 0x5A: # A-Z
digit = char - 0x41
elif 0x30 <= char <= 0x39:
digit = char - 22 # 0x30-26
elif errors == "strict":
raise UnicodeError("Invalid extended code point '%s'"
   % extended[extpos])

   While raising the UnicodeError() in the last line above, it accesses 
extended[extpos]. However extpos was incremented by 1 a few lines above that. 
This causes two errors:
   1) The UnicodeError() prints the wrong character (the one after the 
character we want)
   2) If the previous extpos was the last character in the string, then 
attempting to print character at extpos+1 will raise an IndexError.

--
components: Library (Lib)
messages: 295127
nosy: Vikram Hegde
priority: normal
severity: normal
status: open
title: punycode codec raises IndexError in decode_generalized_number()
type: crash
versions: Python 3.6

___
Python tracker 
<http://bugs.python.org/issue30566>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30566] punycode codec raises IndexError in decode_generalized_number()

2017-06-04 Thread Vikram Hegde

Changes by Vikram Hegde :


--
nosy:  -Vikram Hegde

___
Python tracker 
<http://bugs.python.org/issue30566>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30566] punycode codec raises IndexError in decode_generalized_number()

2017-06-06 Thread Vikram Hegde

Vikram Hegde added the comment:

I have a patch for this problem but my contributor agreement has not been 
accepted yet, so I can't do a pull request.

Use the python package tldextract to trigger the bug. Here is a sample

Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 12:22:00) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tldextract
>>> tldextract.extract("xn--w&")
Traceback (most recent call last):
  File 
"/home/vikram-work/anaconda3/envs/pefeatextract-debug/lib/python3.6/encodings/punycode.py",
 line 207, in decode
res = punycode_decode(input, errors)
  File 
"/home/vikram-work/anaconda3/envs/pefeatextract-debug/lib/python3.6/encodings/punycode.py",
 line 194, in punycode_decode
return insertion_sort(base, extended, errors)
  File 
"/home/vikram-work/anaconda3/envs/pefeatextract-debug/lib/python3.6/encodings/punycode.py",
 line 165, in insertion_sort
bias, errors)
  File 
"/home/vikram-work/anaconda3/envs/pefeatextract-debug/lib/python3.6/encodings/punycode.py",
 line 146, in decode_generalized_number
% extended[extpos])
IndexError: string index out of range

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

Traceback (most recent call last):
  File "", line 1, in 
  File 
"/home/vikram-work/anaconda3/envs/pefeatextract-debug/lib/python3.6/site-packages/tldextract/tldextract.py",
 line 358, in extract
return TLD_EXTRACTOR(url)
  File 
"/home/vikram-work/anaconda3/envs/pefeatextract-debug/lib/python3.6/site-packages/tldextract/tldextract.py",
 line 237, in __call__
translations = [decode_punycode(label).lower() for label in labels]
  File 
"/home/vikram-work/anaconda3/envs/pefeatextract-debug/lib/python3.6/site-packages/tldextract/tldextract.py",
 line 237, in 
translations = [decode_punycode(label).lower() for label in labels]
  File 
"/home/vikram-work/anaconda3/envs/pefeatextract-debug/lib/python3.6/site-packages/tldextract/tldextract.py",
 line 232, in decode_punycode
return idna.decode(label.encode('ascii'))
  File 
"/home/vikram-work/anaconda3/envs/pefeatextract-debug/lib/python3.6/site-packages/idna/core.py",
 line 384, in decode
result.append(ulabel(label))
  File 
"/home/vikram-work/anaconda3/envs/pefeatextract-debug/lib/python3.6/site-packages/idna/core.py",
 line 302, in ulabel
label = label.decode('punycode')
IndexError: decoding with 'punycode' codec failed (IndexError: string index out 
of range)
>>>

--
nosy: +Vikram Hegde

___
Python tracker 
<http://bugs.python.org/issue30566>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30566] punycode codec raises IndexError in decode_generalized_number()

2017-06-07 Thread Vikram Hegde

Changes by Vikram Hegde :


--
pull_requests: +2053

___
Python tracker 
<http://bugs.python.org/issue30566>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com