Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16bb545

Browse files
committed
merge with 3.3
2 parents a0e41a2 + 5f9459f commit 16bb545

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

Lib/test/test_codecs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ def test_surrogatepass_handler(self):
666666
self.assertEqual(b"\xf0\x90\xbf\xbf\xed\xa0\x80".decode("utf-8", "surrogatepass"),
667667
"\U00010fff\uD800")
668668
self.assertTrue(codecs.lookup_error("surrogatepass"))
669+
with self.assertRaises(UnicodeDecodeError):
670+
b"abc\xed\xa0".decode("utf-8", "surrogatepass")
669671

670672
@unittest.skipUnless(sys.platform == 'win32',
671673
'cp65001 is a Windows-only codec')

Python/codecs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,10 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
791791
/* Try decoding a single surrogate character. If
792792
there are more, let the codec call us again. */
793793
p += start;
794-
if ((p[0] & 0xf0) == 0xe0 ||
795-
(p[1] & 0xc0) == 0x80 ||
796-
(p[2] & 0xc0) == 0x80) {
794+
if (strlen(p) > 2 &&
795+
((p[0] & 0xf0) == 0xe0 ||
796+
(p[1] & 0xc0) == 0x80 ||
797+
(p[2] & 0xc0) == 0x80)) {
797798
/* it's a three-byte code */
798799
ch = ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) + (p[2] & 0x3f);
799800
if (ch < 0xd800 || ch > 0xdfff)

0 commit comments

Comments
 (0)