summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-18 00:49:55 +0200
committerwm4 <wm4@nowhere>2014-09-18 00:49:55 +0200
commit6c3d25e6f5f09a110ad0fffaeeea6a65ee5d228b (patch)
treee904c8cd346ccbd640412d1e9f628fff9197b526 /sub
parenta522441bbe6817798ca58b93d7adb180a9598640 (diff)
downloadmpv-6c3d25e6f5f09a110ad0fffaeeea6a65ee5d228b.tar.bz2
mpv-6c3d25e6f5f09a110ad0fffaeeea6a65ee5d228b.tar.xz
command: allow using ASS tags on OSD messages
We don't allow this by default, because it would be silly if random external data (like filenames or file tags) could accidentally trigger them. Add a property that magically disables this ASS tag escaping. Note that malicious input could still disable ASS tag escaping by itself. This would be annoying but harmless.
Diffstat (limited to 'sub')
-rw-r--r--sub/osd.h2
-rw-r--r--sub/osd_dummy.c3
-rw-r--r--sub/osd_libass.c14
3 files changed, 17 insertions, 2 deletions
diff --git a/sub/osd.h b/sub/osd.h
index 2a5bf71b05..2662e2b67f 100644
--- a/sub/osd.h
+++ b/sub/osd.h
@@ -219,6 +219,8 @@ void osd_destroy_backend(struct osd_state *osd);
// doesn't need locking
void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function);
+extern const char *osd_ass_0;
+extern const char *osd_ass_1;
// defined in backend, but locks if required
void osd_object_get_resolution(struct osd_state *osd, int obj,
diff --git a/sub/osd_dummy.c b/sub/osd_dummy.c
index 6fc78ab368..b9178e1925 100644
--- a/sub/osd_dummy.c
+++ b/sub/osd_dummy.c
@@ -6,6 +6,9 @@
#include "talloc.h"
#include "osd.h"
+const char *osd_ass_0 = "";
+const char *osd_ass_1 = "";
+
void osd_init_backend(struct osd_state *osd)
{
}
diff --git a/sub/osd_libass.c b/sub/osd_libass.c
index 1fea27ced6..03d5040dbf 100644
--- a/sub/osd_libass.c
+++ b/sub/osd_libass.c
@@ -159,8 +159,13 @@ void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function)
snprintf(buffer, buffer_size, "\xFF%c", osd_function);
}
+// Same trick as above: never valid UTF-8, so we expect it's free for use.
+const char *osd_ass_0 = "\xFD";
+const char *osd_ass_1 = "\xFE";
+
static void mangle_ass(bstr *dst, const char *in)
{
+ bool escape_ass = true;
while (*in) {
// As used by osd_get_function_sym().
if (in[0] == '\xFF' && in[1]) {
@@ -170,11 +175,16 @@ static void mangle_ass(bstr *dst, const char *in)
in += 2;
continue;
}
- if (*in == '{')
+ if (*in == '\xFD' || *in == '\xFE') {
+ escape_ass = *in == '\xFE';
+ in += 1;
+ continue;
+ }
+ if (escape_ass && *in == '{')
bstr_xappend(NULL, dst, bstr0("\\"));
bstr_xappend(NULL, dst, (bstr){(char *)in, 1});
// Break ASS escapes with U+2060 WORD JOINER
- if (*in == '\\')
+ if (escape_ass && *in == '\\')
mp_append_utf8_bstr(NULL, dst, 0x2060);
in++;
}