Skip to content

Commit a113e01

Browse files
committed
Branch merge
2 parents 8f423c9 + a0b5c46 commit a113e01

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

Lib/test/test_codecs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,8 @@ def test_surrogatepass_handler(self):
668668
self.assertTrue(codecs.lookup_error("surrogatepass"))
669669
with self.assertRaises(UnicodeDecodeError):
670670
b"abc\xed\xa0".decode("utf-8", "surrogatepass")
671+
with self.assertRaises(UnicodeDecodeError):
672+
b"abc\xed\xa0z".decode("utf-8", "surrogatepass")
671673

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

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 3.3.1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #16336: fix input checking in the surrogatepass error handler.
16+
Patch by Serhiy Storchaka.
17+
1518
- Issue #8401: assigning an int to a bytearray slice (e.g. b[3:4] = 5) now
1619
raises an error.
1720

Python/codecs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +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 (strlen(p) > 2 &&
795-
((p[0] & 0xf0) == 0xe0 ||
796-
(p[1] & 0xc0) == 0x80 ||
797-
(p[2] & 0xc0) == 0x80)) {
794+
if (PyBytes_GET_SIZE(object) - start >= 3 &&
795+
(p[0] & 0xf0) == 0xe0 &&
796+
(p[1] & 0xc0) == 0x80 &&
797+
(p[2] & 0xc0) == 0x80) {
798798
/* it's a three-byte code */
799799
ch = ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) + (p[2] & 0x3f);
800800
if (ch < 0xd800 || ch > 0xdfff)

0 commit comments

Comments
 (0)