Browse code

apetag: do not create invalid APE tags

APEv2 specifications forbids non-ascii keys.

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2013/05/29 23:01:15
Showing 1 changed files
... ...
@@ -170,6 +170,12 @@ int64_t ff_ape_parse_tag(AVFormatContext *s)
170 170
     return tag_start;
171 171
 }
172 172
 
173
+static int string_is_ascii(const uint8_t *str)
174
+{
175
+    while (*str && *str >= 0x20 && *str <= 0x7e ) str++;
176
+    return !*str;
177
+}
178
+
173 179
 int ff_ape_write_tag(AVFormatContext *s)
174 180
 {
175 181
     AVDictionaryEntry *e = NULL;
... ...
@@ -193,8 +199,14 @@ int ff_ape_write_tag(AVFormatContext *s)
193 193
     ffio_fill(s->pb, 0, 8);             // reserved
194 194
 
195 195
     while ((e = av_dict_get(s->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {
196
-        int val_len = strlen(e->value);
196
+        int val_len;
197
+
198
+        if (!string_is_ascii(e->key)) {
199
+            av_log(s, AV_LOG_WARNING, "Non ASCII keys are not allowed\n");
200
+            continue;
201
+        }
197 202
 
203
+        val_len = strlen(e->value);
198 204
         avio_wl32(s->pb, val_len);            // value length
199 205
         avio_wl32(s->pb, 0);                  // item flags
200 206
         avio_put_str(s->pb, e->key);          // key