common: validate parsed unicode codepoints value

Fixes UB when converting out of expected range values.

Found by OSS-Fuzz.
This commit is contained in:
Kacper Michajłow 2024-06-22 02:44:18 +02:00
parent 758019bf92
commit 5534e0e1d9
1 changed files with 1 additions and 1 deletions

View File

@ -273,7 +273,7 @@ static bool mp_parse_escape(void *talloc_ctx, bstr *dst, bstr *code)
if (code->start[0] == 'u' && code->len >= 5) { if (code->start[0] == 'u' && code->len >= 5) {
bstr num = bstr_splice(*code, 1, 5); bstr num = bstr_splice(*code, 1, 5);
uint32_t c = bstrtoll(num, &num, 16); uint32_t c = bstrtoll(num, &num, 16);
if (num.len) if (num.len || c > 0x10FFFF)
return false; return false;
if (c >= 0xd800 && c <= 0xdbff) { if (c >= 0xd800 && c <= 0xdbff) {
if (code->len < 5 + 6 // udddd + \udddd if (code->len < 5 + 6 // udddd + \udddd