@@ -4392,37 +4392,34 @@ PyObject *_PyUnicode_DecodeUnicodeInternal(const char *s,
43924392 end = s + size ;
43934393
43944394 while (s < end ) {
4395+ if (end - s < Py_UNICODE_SIZE ) {
4396+ endinpos = end - starts ;
4397+ reason = "truncated input" ;
4398+ goto error ;
4399+ }
43954400 memcpy (p , s , sizeof (Py_UNICODE ));
4401+ #ifdef Py_UNICODE_WIDE
43964402 /* We have to sanity check the raw data, otherwise doom looms for
43974403 some malformed UCS-4 data. */
4398- if (
4399- #ifdef Py_UNICODE_WIDE
4400- * p > unimax || * p < 0 ||
4401- #endif
4402- end - s < Py_UNICODE_SIZE
4403- )
4404- {
4405- startinpos = s - starts ;
4406- if (end - s < Py_UNICODE_SIZE ) {
4407- endinpos = end - starts ;
4408- reason = "truncated input" ;
4409- }
4410- else {
4411- endinpos = s - starts + Py_UNICODE_SIZE ;
4412- reason = "illegal code point (> 0x10FFFF)" ;
4413- }
4414- outpos = p - PyUnicode_AS_UNICODE (v );
4415- if (unicode_decode_call_errorhandler (
4416- errors , & errorHandler ,
4417- "unicode_internal" , reason ,
4418- & starts , & end , & startinpos , & endinpos , & exc , & s ,
4419- & v , & outpos , & p )) {
4420- goto onError ;
4421- }
4404+ if (* p > unimax || * p < 0 ) {
4405+ endinpos = s - starts + Py_UNICODE_SIZE ;
4406+ reason = "illegal code point (> 0x10FFFF)" ;
4407+ goto error ;
44224408 }
4423- else {
4424- p ++ ;
4425- s += Py_UNICODE_SIZE ;
4409+ #endif
4410+ p ++ ;
4411+ s += Py_UNICODE_SIZE ;
4412+ continue ;
4413+
4414+ error :
4415+ startinpos = s - starts ;
4416+ outpos = p - PyUnicode_AS_UNICODE (v );
4417+ if (unicode_decode_call_errorhandler (
4418+ errors , & errorHandler ,
4419+ "unicode_internal" , reason ,
4420+ & starts , & end , & startinpos , & endinpos , & exc , & s ,
4421+ & v , & outpos , & p )) {
4422+ goto onError ;
44264423 }
44274424 }
44284425
0 commit comments