File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -647,6 +647,8 @@ def test_surrogatepass_handler(self):
647647 self .assertTrue (codecs .lookup_error ("surrogatepass" ))
648648 with self .assertRaises (UnicodeDecodeError ):
649649 b"abc\xed \xa0 " .decode ("utf-8" , "surrogatepass" )
650+ with self .assertRaises (UnicodeDecodeError ):
651+ b"abc\xed \xa0 z" .decode ("utf-8" , "surrogatepass" )
650652
651653class UTF7Test (ReadTest ):
652654 encoding = "utf-7"
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ What's New in Python 3.2.4
1010Core and Builtins
1111-----------------
1212
13+ - Issue #16336: fix input checking in the surrogatepass error handler.
14+ Patch by Serhiy Storchaka.
15+
1316- Issue #8401: assigning an int to a bytearray slice (e.g. b[3:4] = 5) now
1417 raises an error.
1518
Original file line number Diff line number Diff line change @@ -821,10 +821,10 @@ PyCodec_SurrogatePassErrors(PyObject *exc)
821821 /* Try decoding a single surrogate character. If
822822 there are more, let the codec call us again. */
823823 p += start ;
824- if (strlen ( p ) > 2 &&
825- (( p [0 ] & 0xf0 ) == 0xe0 ||
826- (p [1 ] & 0xc0 ) == 0x80 ||
827- (p [2 ] & 0xc0 ) == 0x80 ) ) {
824+ if (PyBytes_GET_SIZE ( object ) - start >= 3 &&
825+ (p [0 ] & 0xf0 ) == 0xe0 &&
826+ (p [1 ] & 0xc0 ) == 0x80 &&
827+ (p [2 ] & 0xc0 ) == 0x80 ) {
828828 /* it's a three-byte code */
829829 ch = ((p [0 ] & 0x0f ) << 12 ) + ((p [1 ] & 0x3f ) << 6 ) + (p [2 ] & 0x3f );
830830 if (ch < 0xd800 || ch > 0xdfff )
You can’t perform that action at this time.
0 commit comments