summaryrefslogtreecommitdiffstats
path: root/common/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/common.c')
-rw-r--r--common/common.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/common/common.c b/common/common.c
index 829dbde50c..eead096d5a 100644
--- a/common/common.c
+++ b/common/common.c
@@ -1,18 +1,18 @@
/*
* This file is part of mpv.
*
- * mpv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * mpv is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
* mpv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with mpv. If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
@@ -25,6 +25,7 @@
#include "misc/bstr.h"
#include "misc/ctype.h"
#include "common/common.h"
+#include "osdep/strnlen.h"
#define appendf(ptr, ...) \
do {(*(ptr)) = talloc_asprintf_append_buffer(*(ptr), __VA_ARGS__);} while(0)
@@ -187,9 +188,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;