aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorPeter Ross <pross@xvid.org>2014-04-18 14:49:40 +1000
committerCarl Eugen Hoyos <cehoyos@ag.or.at>2014-04-19 13:28:22 +0200
commit7f8aa37bc3666d060b3eb2baa02fcea3597a22fd (patch)
tree94709dcb2b847cd5255b3ca347b0d04aebda846a /libavformat
parent5219e20d58e15305e188ba60a75bfc37a1f82341 (diff)
downloadffmpeg-7f8aa37bc3666d060b3eb2baa02fcea3597a22fd.tar.gz
ff_id3v2_read: add option to limit ID3 magic number search
Several chunked formats (AIFF, IFF,DSF) store ID3 metadata within an 'ID3 ' chunk tag. If such chunks are stored sequentially, it is possible for the ID3v2 parser to confuse the chunk tag for the ID3 magic number. e.g. [1st chunk tag ('ID3 ') | chunk size] [ID3 magic number | metadata ...] [2nd chunk tag ('ID3 ') | chunk size] [ID3 magic number | metadata ...] Fixes ticket #3530. Signed-off-by: Peter Ross <pross@xvid.org> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 5331773cc33ba26b9e26ace643d926219e46a17b) Conflicts: libavformat/dsfdec.c libavformat/id3v2.c
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/aiffdec.c2
-rw-r--r--libavformat/asfdec.c2
-rw-r--r--libavformat/id3v2.c15
-rw-r--r--libavformat/id3v2.h4
-rw-r--r--libavformat/omadec.c2
-rw-r--r--libavformat/utils.c2
6 files changed, 20 insertions, 7 deletions
diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index 4a2629888b..396abb162d 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -237,7 +237,7 @@ static int aiff_read_header(AVFormatContext *s)
break;
case MKTAG('I', 'D', '3', ' '):
position = avio_tell(pb);
- ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
+ ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta, size);
if (id3v2_extra_meta)
if ((ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0) {
ff_id3v2_free_extra_meta(&id3v2_extra_meta);
diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index de42b45a8e..74201cff1a 100644
--- a/libavformat/asfdec.c
+++ b/libavformat/asfdec.c
@@ -268,7 +268,7 @@ static void get_id3_tag(AVFormatContext *s, int len)
{
ID3v2ExtraMeta *id3v2_extra_meta = NULL;
- ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
+ ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta, len);
if (id3v2_extra_meta)
ff_id3v2_parse_apic(s, &id3v2_extra_meta);
ff_id3v2_free_extra_meta(&id3v2_extra_meta);
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 2e8d06d6b0..8fdcc8a032 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -777,17 +777,28 @@ seek:
return;
}
-void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta)
+void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta,
+ unsigned int max_search_size)
{
int len, ret;
uint8_t buf[ID3v2_HEADER_SIZE];
int found_header;
- int64_t off;
+ int64_t start, off;
+ if (max_search_size && max_search_size < ID3v2_HEADER_SIZE)
+ return;
+
+ start = avio_tell(s->pb);
do {
/* save the current offset in case there's nothing to read/skip */
off = avio_tell(s->pb);
ret = avio_read(s->pb, buf, ID3v2_HEADER_SIZE);
+ if (max_search_size && off - start >= max_search_size - ID3v2_HEADER_SIZE) {
+ avio_seek(s->pb, off, SEEK_SET);
+ break;
+ }
+
+ ret = avio_read(s->pb, buf, ID3v2_HEADER_SIZE);
if (ret != ID3v2_HEADER_SIZE) {
avio_seek(s->pb, off, SEEK_SET);
break;
diff --git a/libavformat/id3v2.h b/libavformat/id3v2.h
index f7270106a1..4fe59a5477 100644
--- a/libavformat/id3v2.h
+++ b/libavformat/id3v2.h
@@ -93,8 +93,10 @@ int ff_id3v2_tag_len(const uint8_t *buf);
* Read an ID3v2 tag, including supported extra metadata
* @param extra_meta If not NULL, extra metadata is parsed into a list of
* ID3v2ExtraMeta structs and *extra_meta points to the head of the list
+ * @param[opt] max_search_search restrict ID3 magic number search (bytes from start)
*/
-void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta);
+void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta,
+ unsigned int max_search_size);
/**
* Initialize an ID3v2 tag.
diff --git a/libavformat/omadec.c b/libavformat/omadec.c
index 8d29675c1c..34d63a377c 100644
--- a/libavformat/omadec.c
+++ b/libavformat/omadec.c
@@ -275,7 +275,7 @@ static int oma_read_header(AVFormatContext *s)
ID3v2ExtraMeta *extra_meta = NULL;
OMAContext *oc = s->priv_data;
- ff_id3v2_read(s, ID3v2_EA3_MAGIC, &extra_meta);
+ ff_id3v2_read(s, ID3v2_EA3_MAGIC, &extra_meta, 0);
ret = avio_read(s->pb, buf, EA3_HEADER_SIZE);
if (ret < EA3_HEADER_SIZE)
return -1;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index d32f584197..821b23d642 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -620,7 +620,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
/* e.g. AVFMT_NOFILE formats will not have a AVIOContext */
if (s->pb)
- ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
+ ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta, 0);
if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->iformat->read_header)
if ((ret = s->iformat->read_header(s)) < 0)