From a6bc7ed17d202107208bbe637ca92d5886c3d686 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 5 Apr 2009 18:39:10 +0100 Subject: Fix handling of the length of UTF-16 content sourced from, e.g., ID3 tags. This avoids use of strlen(), which doesn't cope well with UTF-16, and also has the ID3 parser double-NUL-terminate the buffered string. --- src/xine-engine/info_helper.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/xine-engine') diff --git a/src/xine-engine/info_helper.c b/src/xine-engine/info_helper.c index 34d1bbdba..6ce9bcd38 100644 --- a/src/xine-engine/info_helper.c +++ b/src/xine-engine/info_helper.c @@ -251,7 +251,15 @@ static void meta_info_set_unlocked_encoding(xine_stream_t *stream, int info, con size_t inbytesleft, outbytesleft; inbuf = (ICONV_CONST char *)value; - inbytesleft = strlen(value); + if (!strncmp (enc, "UTF-16", 6) || !strncmp (enc, "UCS-2", 5)) + { + /* strlen() won't work with UTF-16* or UCS-2* */ + inbytesleft = 0; + while (value[inbytesleft] || value[inbytesleft + 1]) + inbytesleft += 2; + } /* ... do we need to handle UCS-4? Probably not. */ + else + inbytesleft = strlen(value); outbytesleft = 4 * inbytesleft; /* estimative (max) */ outbuf = utf8_value = malloc(outbytesleft+1); -- cgit v1.2.3