mirror of
https://github.com/python/cpython.git
synced 2025-08-25 03:04:55 +00:00
bpo-24214: Fixed the UTF-8 and UTF-16 incremental decoders. (GH-14304)
* The UTF-8 incremental decoders fails now fast if encounter
a sequence that can't be handled by the error handler.
* The UTF-16 incremental decoders with the surrogatepass error
handler decodes now a lone low surrogate with final=False.
(cherry picked from commit 894263ba80
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
26fe6c3537
commit
d32594ad27
4 changed files with 36 additions and 6 deletions
|
@ -4937,11 +4937,15 @@ unicode_decode_utf8(const char *s, Py_ssize_t size,
|
|||
endinpos = startinpos + 1;
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
if (s == end || consumed) {
|
||||
if (consumed && (unsigned char)s[0] == 0xED && end - s == 2
|
||||
&& (unsigned char)s[1] >= 0xA0 && (unsigned char)s[1] <= 0xBF)
|
||||
{
|
||||
/* Truncated surrogate code in range D800-DFFF */
|
||||
goto End;
|
||||
}
|
||||
/* fall through */
|
||||
case 3:
|
||||
case 4:
|
||||
errmsg = "invalid continuation byte";
|
||||
startinpos = s - starts;
|
||||
endinpos = startinpos + ch - 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue