History

id3v2enc: fix writing frame sizes for ID3v2.3

Frame sizes in ID3v2.3 are not synchsafe, they are simply 32be numbers. In practice this bug is not noticeable unless the frame size takes more than 7 bits (which is almost never for text frames).

Anton Khirnov committed 14 years ago

Commit 24fe1a31 parent 411225a1 file · +15 −11Browse files

Unified · Split

libavformat/id3v2enc.c+15−11
@@ -45,7 +45,7 @@ static int string_is_ascii(const uint8_t *str) · 44 unmodified lines
4545 * according to encoding (only UTF-8 or UTF-16+BOM supported).
4646 * @return number of bytes written or a negative error code.
4747 */
48−static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2,
48+static int id3v2_put_ttag(ID3v2EncContext *id3, AVIOContext *avioc, const char *str1, const char *str2,
4949 uint32_t tag, enum ID3v2Encoding enc)
5050 {
5151 int len;
@@ -73,17 +73,21 @@ static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2 · 21 unmodified lines
7373 put(dyn_buf, str2);
7474 len = avio_close_dyn_buf(dyn_buf, &pb);
7575
76− avio_wb32(s->pb, tag);
77− id3v2_put_size(s->pb, len);
78− avio_wb16(s->pb, 0);
79− avio_write(s->pb, pb, len);
76+ avio_wb32(avioc, tag);
77+ /* ID3v2.3 frame size is not synchsafe */
78+ if (id3->version == 3)
79+ avio_wb32(avioc, len);
80+ else
81+ id3v2_put_size(avioc, len);
82+ avio_wb16(avioc, 0);
83+ avio_write(avioc, pb, len);
8084
8185 av_freep(&pb);
8286 return len + ID3v2_HEADER_SIZE;
8387 }
8488
85−static int id3v2_check_write_tag(AVFormatContext *s, AVDictionaryEntry *t, const char table[][4],
86− enum ID3v2Encoding enc)
89+static int id3v2_check_write_tag(ID3v2EncContext *id3, AVIOContext *pb, AVDictionaryEntry *t,
90+ const char table[][4], enum ID3v2Encoding enc)
8791 {
8892 uint32_t tag;
8993 int i;
@@ -93,7 +97,7 @@ static int id3v2_check_write_tag(AVFormatContext *s, AVDictionaryEntry *t, const · 3 unmodified lines
9397 tag = AV_RB32(t->key);
9498 for (i = 0; *table[i]; i++)
9599 if (tag == AV_RB32(table[i]))
96− return id3v2_put_ttag(s, t->value, NULL, tag, enc);
100+ return id3v2_put_ttag(id3, pb, t->value, NULL, tag, enc);
97101 return -1;
98102 }
99103
@@ -124,18 +128,18 @@ int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3) · 24 unmodified lines
124128 while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
125129 int ret;
126130
127− if ((ret = id3v2_check_write_tag(s, t, ff_id3v2_tags, enc)) > 0) {
131+ if ((ret = id3v2_check_write_tag(id3, s->pb, t, ff_id3v2_tags, enc)) > 0) {
128132 id3->len += ret;
129133 continue;
130134 }
131− if ((ret = id3v2_check_write_tag(s, t, id3->version == 3 ?
135+ if ((ret = id3v2_check_write_tag(id3, s->pb, t, id3->version == 3 ?
132136 ff_id3v2_3_tags : ff_id3v2_4_tags, enc)) > 0) {
133137 id3->len += ret;
134138 continue;
135139 }
136140
137141 /* unknown tag, write as TXXX frame */
138− if ((ret = id3v2_put_ttag(s, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0)
142+ if ((ret = id3v2_put_ttag(id3, s->pb, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0)
139143 return ret;
140144 id3->len += ret;
141145 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t