diff options
author | wm4 <wm4@nowhere> | 2020-08-16 02:56:38 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-08-16 02:57:26 +0200 |
commit | 7f67c5250a627c13e8797ff6fa5e42deec50bfdd (patch) | |
tree | e93c58c5cc1be018b77c96cb6a87a0a22f7d6887 /player | |
parent | e27c523a10708b7265c33a4bae631663df4bb297 (diff) | |
download | mpv-7f67c5250a627c13e8797ff6fa5e42deec50bfdd.tar.bz2 mpv-7f67c5250a627c13e8797ff6fa5e42deec50bfdd.tar.xz |
lua: pass strings with embedded zeros as byte arrays
This was a vague idea how to handle passing byte arrays from Lua to the
mpv command interface in a somewhat reasonable way. The idea was
cancelled, but leave the Lua part of it, since it might get useful
later, and prevents passing (and silently cutting off) such byte
strings.
Barely tested, let's say not tested at all.
Diffstat (limited to 'player')
-rw-r--r-- | player/lua.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/player/lua.c b/player/lua.c index 440e3c6ff8..97ec8d33a4 100644 --- a/player/lua.c +++ b/player/lua.c @@ -678,10 +678,21 @@ static void makenode(void *tmp, mpv_node *dst, lua_State *L, int t) dst->format = MPV_FORMAT_FLAG; dst->u.flag = !!lua_toboolean(L, t); break; - case LUA_TSTRING: - dst->format = MPV_FORMAT_STRING; - dst->u.string = talloc_strdup(tmp, lua_tostring(L, t)); + case LUA_TSTRING: { + size_t len = 0; + char *s = (char *)lua_tolstring(L, t, &len); + bool has_zeros = !!memchr(s, 0, len); + if (has_zeros) { + mpv_byte_array *ba = talloc_zero(tmp, mpv_byte_array); + *ba = (mpv_byte_array){talloc_memdup(tmp, s, len), len}; + dst->format = MPV_FORMAT_BYTE_ARRAY; + dst->u.ba = ba; + } else { + dst->format = MPV_FORMAT_STRING; + dst->u.string = talloc_strdup(tmp, s); + } break; + } case LUA_TTABLE: { // Lua uses the same type for arrays and maps, so guess the correct one. int format = MPV_FORMAT_NONE; |