gh-101180: Fix a bug where iso2022_jp_3 and iso2022_jp_2004 codecs read out of bounds (gh-111695)

This commit is contained in:
Masayuki Moriyama 2023-11-06 19:59:22 +09:00 • committed by GitHub
parent ba8aa1fd37
commit c8faa3568a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 3 deletions

View file

@ -207,8 +207,9 @@ ENCODER(iso2022)
encoded = MAP_UNMAPPABLE;
for (dsg = CONFIG_DESIGNATIONS; dsg->mark; dsg++) {
Py_UCS4 buf[2] = {c, 0};
Py_ssize_t length = 1;
encoded = dsg->encoder(codec, &c, &length);
encoded = dsg->encoder(codec, buf, &length);
if (encoded == MAP_MULTIPLE_AVAIL) {
/* this implementation won't work for pair
* of non-bmp characters. */
@ -217,9 +218,11 @@ ENCODER(iso2022)
return MBERR_TOOFEW;
length = -1;
}
else
else {
buf[1] = INCHAR2;
length = 2;
encoded = dsg->encoder(codec, &c, &length);
}
encoded = dsg->encoder(codec, buf, &length);
if (encoded != MAP_UNMAPPABLE) {
insize = length;
break;