Skip to content

Commit 455695f

Browse files
author
antoine.pitrou
committed
#2242: utf7 decoding crashes on bogus input on some Windows/MSVC versions
git-svn-id: http://svn.python.org/projects/python/trunk@65227 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 0143d01 commit 455695f

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

Lib/test/test_unicode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ def test_codecs_utf7(self):
532532

533533
self.assertEqual(unicode('+3ADYAA-', 'utf-7', 'replace'), u'\ufffd')
534534

535+
# Issue #2242: crash on some Windows/MSVC versions
536+
self.assertRaises(UnicodeDecodeError, '+\xc1'.decode, 'utf-7')
537+
535538
def test_codecs_utf8(self):
536539
self.assertEqual(u''.encode('utf-8'), '')
537540
self.assertEqual(u'\u20ac'.encode('utf-8'), '\xe2\x82\xac')

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ PyObject *PyUnicode_DecodeUTF7Stateful(const char *s,
15231523
while (s < e) {
15241524
Py_UNICODE ch;
15251525
restart:
1526-
ch = *s;
1526+
ch = (unsigned char) *s;
15271527

15281528
if (inShift) {
15291529
if ((ch == '-') || !B64CHAR(ch)) {

0 commit comments

Comments
 (0)