summaryrefslogtreecommitdiffstats
path: root/mpvcore/bstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'mpvcore/bstr.c')
-rw-r--r--mpvcore/bstr.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/mpvcore/bstr.c b/mpvcore/bstr.c
index bbc3885b42..996edb7dfe 100644
--- a/mpvcore/bstr.c
+++ b/mpvcore/bstr.c
@@ -279,6 +279,14 @@ int bstr_decode_utf8(struct bstr s, struct bstr *out_next)
codepoint = (codepoint << 6) | (tmp & ~0xC0);
s.start++; s.len--;
}
+ if (codepoint > 0x10FFFF || (codepoint >= 0xD800 && codepoint <= 0xDFFF))
+ return -1;
+ // Overlong sequences - check taken from libavcodec.
+ // (The only reason we even bother with this is to make libavcodec's
+ // retarded subtitle utf-8 check happy.)
+ unsigned int min = bytes == 2 ? 0x80 : 1 << (5 * bytes - 4);
+ if (codepoint < min)
+ return -1;
}
if (out_next)
*out_next = s;