diff options
author | Luca Barbato <lu_zero@gentoo.org> | 2012-09-20 01:01:43 +0200 |
---|---|---|
committer | Luca Barbato <lu_zero@gentoo.org> | 2012-09-24 22:35:29 +0200 |
commit | 7751e4693dd10ec98c20fbd9887233b575034272 (patch) | |
tree | 54e3ad95d7c65d7b44f937b87d1628b737aa56e3 | |
parent | a716006a7d6371a8f124be49d7ce59bcc28f9e53 (diff) | |
download | ffmpeg-7751e4693dd10ec98c20fbd9887233b575034272.tar.gz |
ogg: check that the expected number of headers had been parsed
Not having the header for a codec is a tell-tale of a broken file.
-rw-r--r-- | libavformat/oggdec.c | 13 | ||||
-rw-r--r-- | libavformat/oggdec.h | 5 | ||||
-rw-r--r-- | libavformat/oggparsecelt.c | 1 | ||||
-rw-r--r-- | libavformat/oggparsedirac.c | 2 | ||||
-rw-r--r-- | libavformat/oggparseflac.c | 6 | ||||
-rw-r--r-- | libavformat/oggparseogm.c | 4 | ||||
-rw-r--r-- | libavformat/oggparseskeleton.c | 1 | ||||
-rw-r--r-- | libavformat/oggparsespeex.c | 3 | ||||
-rw-r--r-- | libavformat/oggparsetheora.c | 3 | ||||
-rw-r--r-- | libavformat/oggparsevorbis.c | 1 |
10 files changed, 34 insertions, 5 deletions
diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index e04a4e7973..c8b2a858f1 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -406,6 +406,7 @@ static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize, s->data_offset = FFMIN(s->data_offset, cur_os->sync_pos); } }else{ + os->nb_header++; os->pstart += os->psize; os->psize = 0; } @@ -445,7 +446,7 @@ static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize, static int ogg_get_headers(AVFormatContext *s) { struct ogg *ogg = s->priv_data; - int ret; + int ret, i; do{ ret = ogg_packet(s, NULL, NULL, NULL, NULL); @@ -453,6 +454,16 @@ static int ogg_get_headers(AVFormatContext *s) return ret; }while (!ogg->headers); + for (i = 0; i < ogg->nstreams; i++) { + struct ogg_stream *os = ogg->streams + i; + + if (os->codec && os->codec->nb_header && + os->nb_header < os->codec->nb_header) { + av_log(s, AV_LOG_ERROR, + "Headers mismatch for stream %d\n", i); + return AVERROR_INVALIDDATA; + } + } av_dlog(s, "found headers\n"); return 0; diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h index 184a628622..fa8a5bc29a 100644 --- a/libavformat/oggdec.h +++ b/libavformat/oggdec.h @@ -51,6 +51,10 @@ struct ogg_codec { * 0 if granule is the end time of the associated packet. */ int granule_is_start; + /** + * Number of expected headers + */ + int nb_header; }; struct ogg_stream { @@ -75,6 +79,7 @@ struct ogg_stream { int incomplete; ///< whether we're expecting a continuation in the next page int page_end; ///< current packet is the last one completed in the page int keyframe_seek; + int nb_header; ///< set to the number of parsed headers void *private; }; diff --git a/libavformat/oggparsecelt.c b/libavformat/oggparsecelt.c index 253ef76032..0deccc2d08 100644 --- a/libavformat/oggparsecelt.c +++ b/libavformat/oggparsecelt.c @@ -93,4 +93,5 @@ const struct ogg_codec ff_celt_codec = { .magic = "CELT ", .magicsize = 8, .header = celt_header, + .nb_header = 2, }; diff --git a/libavformat/oggparsedirac.c b/libavformat/oggparsedirac.c index cc6f7687ba..55a0b59127 100644 --- a/libavformat/oggparsedirac.c +++ b/libavformat/oggparsedirac.c @@ -104,6 +104,7 @@ const struct ogg_codec ff_dirac_codec = { .header = dirac_header, .gptopts = dirac_gptopts, .granule_is_start = 1, + .nb_header = 1, }; const struct ogg_codec ff_old_dirac_codec = { @@ -112,4 +113,5 @@ const struct ogg_codec ff_old_dirac_codec = { .header = old_dirac_header, .gptopts = old_dirac_gptopts, .granule_is_start = 1, + .nb_header = 1, }; diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c index 9860a0eb97..f59b4008dc 100644 --- a/libavformat/oggparseflac.c +++ b/libavformat/oggparseflac.c @@ -88,11 +88,13 @@ old_flac_header (AVFormatContext * s, int idx) const struct ogg_codec ff_flac_codec = { .magic = "\177FLAC", .magicsize = 5, - .header = flac_header + .header = flac_header, + .nb_header = 2, }; const struct ogg_codec ff_old_flac_codec = { .magic = "fLaC", .magicsize = 4, - .header = old_flac_header + .header = old_flac_header, + .nb_header = 0, }; diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c index b52969f9b2..7b3cda221e 100644 --- a/libavformat/oggparseogm.c +++ b/libavformat/oggparseogm.c @@ -156,6 +156,7 @@ const struct ogg_codec ff_ogm_video_codec = { .header = ogm_header, .packet = ogm_packet, .granule_is_start = 1, + .nb_header = 2, }; const struct ogg_codec ff_ogm_audio_codec = { @@ -164,6 +165,7 @@ const struct ogg_codec ff_ogm_audio_codec = { .header = ogm_header, .packet = ogm_packet, .granule_is_start = 1, + .nb_header = 2, }; const struct ogg_codec ff_ogm_text_codec = { @@ -172,6 +174,7 @@ const struct ogg_codec ff_ogm_text_codec = { .header = ogm_header, .packet = ogm_packet, .granule_is_start = 1, + .nb_header = 2, }; const struct ogg_codec ff_ogm_old_codec = { @@ -180,4 +183,5 @@ const struct ogg_codec ff_ogm_old_codec = { .header = ogm_dshow_header, .packet = ogm_packet, .granule_is_start = 1, + .nb_header = 1, }; diff --git a/libavformat/oggparseskeleton.c b/libavformat/oggparseskeleton.c index 62dd14ded1..a49d30be58 100644 --- a/libavformat/oggparseskeleton.c +++ b/libavformat/oggparseskeleton.c @@ -86,4 +86,5 @@ const struct ogg_codec ff_skeleton_codec = { .magic = "fishead", .magicsize = 8, .header = skeleton_header, + .nb_header = 0, }; diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c index e4dfec5218..11b50d5905 100644 --- a/libavformat/oggparsespeex.c +++ b/libavformat/oggparsespeex.c @@ -122,5 +122,6 @@ const struct ogg_codec ff_speex_codec = { .magic = "Speex ", .magicsize = 8, .header = speex_header, - .packet = speex_packet + .packet = speex_packet, + .nb_header = 2, }; diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c index 021d3aefb5..df7a89c09d 100644 --- a/libavformat/oggparsetheora.c +++ b/libavformat/oggparsetheora.c @@ -150,5 +150,6 @@ const struct ogg_codec ff_theora_codec = { .magic = "\200theora", .magicsize = 7, .header = theora_header, - .gptopts = theora_gptopts + .gptopts = theora_gptopts, + .nb_header = 3, }; diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index f762c940f0..396a3e3ea7 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -359,4 +359,5 @@ const struct ogg_codec ff_vorbis_codec = { .magicsize = 7, .header = vorbis_header, .packet = vorbis_packet, + .nb_header = 3, }; |