Fixed parsing of JSON encoded UTF-16 surrogate pairs.

This commit is contained in:
Valentin Bartenev
2017-08-11 18:13:57 +03:00
parent 39a6a4c973
commit 8bb88aaf51

View File

@@ -1375,31 +1375,28 @@ nxt_conf_json_parse_string(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start,
p += 4; p += 4;
if (utf < 0xd800 || utf > 0xdbff || utf_high) { if (utf_high != 0) {
if (nxt_slow_path(utf < 0xdc00 || utf > 0xdfff)) {
return NULL;
}
utf = ((utf_high - 0xd800) << 10) + (utf - 0xdc00) + 0x10000;
break; break;
} }
utf_high = utf; if (utf < 0xd800 || utf > 0xdfff) {
utf = 0;
if (p[0] != '\\' || p[1] != 'u') {
break; break;
} }
p += 2; if (utf > 0xdbff || p[0] != '\\' || p[1] != 'u') {
}
if (utf_high != 0) {
if (nxt_slow_path(utf_high < 0xd800
|| utf_high > 0xdbff
|| utf < 0xdc00
|| utf > 0xdfff))
{
/* Invalid surrogate pair. */
return NULL; return NULL;
} }
utf = ((utf_high - 0xd800) << 10) + (utf - 0xdc00); p += 2;
utf_high = utf;
utf = 0;
} }
s = nxt_utf8_encode(s, utf); s = nxt_utf8_encode(s, utf);