summaryrefslogtreecommitdiffstats
path: root/common/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/common.c')
-rw-r--r--common/common.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/common/common.c b/common/common.c
index d77e188a24..41647b3450 100644
--- a/common/common.c
+++ b/common/common.c
@@ -187,9 +187,20 @@ static bool mp_parse_escape(void *talloc_ctx, bstr *dst, bstr *code)
}
if (code->start[0] == 'u' && code->len >= 5) {
bstr num = bstr_splice(*code, 1, 5);
- int c = bstrtoll(num, &num, 16);
+ uint32_t c = bstrtoll(num, &num, 16);
if (num.len)
return false;
+ if (c >= 0xd800 && c <= 0xdbff) {
+ if (code->len < 5 + 6 // udddd + \udddd
+ || code->start[5] != '\\' || code->start[6] != 'u')
+ return false;
+ *code = bstr_cut(*code, 5 + 1);
+ bstr num2 = bstr_splice(*code, 1, 5);
+ uint32_t c2 = bstrtoll(num2, &num2, 16);
+ if (num2.len || c2 < 0xdc00 || c2 > 0xdfff)
+ return false;
+ c = ((c - 0xd800) << 10) + 0x10000 + (c2 - 0xdc00);
+ }
mp_append_utf8_bstr(talloc_ctx, dst, c);
*code = bstr_cut(*code, 5);
return true;