Avoid writing the trailing NUL byte for id3v1 tags if length reaches max length.

Based on an idea by: Michael Niedermayer <michae...@gmx.at>
---
 libavformat/mp3enc.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index fac39d9..4bd2eed 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -37,8 +37,10 @@ static int id3v1_set_string(AVFormatContext *s, const char 
*key,
                             uint8_t *buf, int buf_size)
 {
     AVDictionaryEntry *tag;
-    if ((tag = av_dict_get(s->metadata, key, NULL, 0)))
-        av_strlcpy(buf, tag->value, buf_size);
+    if ((tag = av_dict_get(s->metadata, key, NULL, 0))) {
+        buf_size = FFMIN(buf_size, strlen(tag->value));
+        memcpy(buf, tag->value, buf_size);
+    }
     return !!tag;
 }
 
-- 
1.7.7.3

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to