File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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' )
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments