Commit 7751e469 authored by Luca Barbato's avatar Luca Barbato

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.
parent a716006a
...@@ -406,6 +406,7 @@ static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize, ...@@ -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); s->data_offset = FFMIN(s->data_offset, cur_os->sync_pos);
} }
}else{ }else{
os->nb_header++;
os->pstart += os->psize; os->pstart += os->psize;
os->psize = 0; os->psize = 0;
} }
...@@ -445,7 +446,7 @@ static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize, ...@@ -445,7 +446,7 @@ static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize,
static int ogg_get_headers(AVFormatContext *s) static int ogg_get_headers(AVFormatContext *s)
{ {
struct ogg *ogg = s->priv_data; struct ogg *ogg = s->priv_data;
int ret; int ret, i;
do{ do{
ret = ogg_packet(s, NULL, NULL, NULL, NULL); ret = ogg_packet(s, NULL, NULL, NULL, NULL);
...@@ -453,6 +454,16 @@ static int ogg_get_headers(AVFormatContext *s) ...@@ -453,6 +454,16 @@ static int ogg_get_headers(AVFormatContext *s)
return ret; return ret;
}while (!ogg->headers); }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"); av_dlog(s, "found headers\n");
return 0; return 0;
......
...@@ -51,6 +51,10 @@ struct ogg_codec { ...@@ -51,6 +51,10 @@ struct ogg_codec {
* 0 if granule is the end time of the associated packet. * 0 if granule is the end time of the associated packet.
*/ */
int granule_is_start; int granule_is_start;
/**
* Number of expected headers
*/
int nb_header;
}; };
struct ogg_stream { struct ogg_stream {
...@@ -75,6 +79,7 @@ struct ogg_stream { ...@@ -75,6 +79,7 @@ struct ogg_stream {
int incomplete; ///< whether we're expecting a continuation in the next page 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 page_end; ///< current packet is the last one completed in the page
int keyframe_seek; int keyframe_seek;
int nb_header; ///< set to the number of parsed headers
void *private; void *private;
}; };
......
...@@ -93,4 +93,5 @@ const struct ogg_codec ff_celt_codec = { ...@@ -93,4 +93,5 @@ const struct ogg_codec ff_celt_codec = {
.magic = "CELT ", .magic = "CELT ",
.magicsize = 8, .magicsize = 8,
.header = celt_header, .header = celt_header,
.nb_header = 2,
}; };
...@@ -104,6 +104,7 @@ const struct ogg_codec ff_dirac_codec = { ...@@ -104,6 +104,7 @@ const struct ogg_codec ff_dirac_codec = {
.header = dirac_header, .header = dirac_header,
.gptopts = dirac_gptopts, .gptopts = dirac_gptopts,
.granule_is_start = 1, .granule_is_start = 1,
.nb_header = 1,
}; };
const struct ogg_codec ff_old_dirac_codec = { const struct ogg_codec ff_old_dirac_codec = {
...@@ -112,4 +113,5 @@ const struct ogg_codec ff_old_dirac_codec = { ...@@ -112,4 +113,5 @@ const struct ogg_codec ff_old_dirac_codec = {
.header = old_dirac_header, .header = old_dirac_header,
.gptopts = old_dirac_gptopts, .gptopts = old_dirac_gptopts,
.granule_is_start = 1, .granule_is_start = 1,
.nb_header = 1,
}; };
...@@ -88,11 +88,13 @@ old_flac_header (AVFormatContext * s, int idx) ...@@ -88,11 +88,13 @@ old_flac_header (AVFormatContext * s, int idx)
const struct ogg_codec ff_flac_codec = { const struct ogg_codec ff_flac_codec = {
.magic = "\177FLAC", .magic = "\177FLAC",
.magicsize = 5, .magicsize = 5,
.header = flac_header .header = flac_header,
.nb_header = 2,
}; };
const struct ogg_codec ff_old_flac_codec = { const struct ogg_codec ff_old_flac_codec = {
.magic = "fLaC", .magic = "fLaC",
.magicsize = 4, .magicsize = 4,
.header = old_flac_header .header = old_flac_header,
.nb_header = 0,
}; };
...@@ -156,6 +156,7 @@ const struct ogg_codec ff_ogm_video_codec = { ...@@ -156,6 +156,7 @@ const struct ogg_codec ff_ogm_video_codec = {
.header = ogm_header, .header = ogm_header,
.packet = ogm_packet, .packet = ogm_packet,
.granule_is_start = 1, .granule_is_start = 1,
.nb_header = 2,
}; };
const struct ogg_codec ff_ogm_audio_codec = { const struct ogg_codec ff_ogm_audio_codec = {
...@@ -164,6 +165,7 @@ const struct ogg_codec ff_ogm_audio_codec = { ...@@ -164,6 +165,7 @@ const struct ogg_codec ff_ogm_audio_codec = {
.header = ogm_header, .header = ogm_header,
.packet = ogm_packet, .packet = ogm_packet,
.granule_is_start = 1, .granule_is_start = 1,
.nb_header = 2,
}; };
const struct ogg_codec ff_ogm_text_codec = { const struct ogg_codec ff_ogm_text_codec = {
...@@ -172,6 +174,7 @@ const struct ogg_codec ff_ogm_text_codec = { ...@@ -172,6 +174,7 @@ const struct ogg_codec ff_ogm_text_codec = {
.header = ogm_header, .header = ogm_header,
.packet = ogm_packet, .packet = ogm_packet,
.granule_is_start = 1, .granule_is_start = 1,
.nb_header = 2,
}; };
const struct ogg_codec ff_ogm_old_codec = { const struct ogg_codec ff_ogm_old_codec = {
...@@ -180,4 +183,5 @@ const struct ogg_codec ff_ogm_old_codec = { ...@@ -180,4 +183,5 @@ const struct ogg_codec ff_ogm_old_codec = {
.header = ogm_dshow_header, .header = ogm_dshow_header,
.packet = ogm_packet, .packet = ogm_packet,
.granule_is_start = 1, .granule_is_start = 1,
.nb_header = 1,
}; };
...@@ -86,4 +86,5 @@ const struct ogg_codec ff_skeleton_codec = { ...@@ -86,4 +86,5 @@ const struct ogg_codec ff_skeleton_codec = {
.magic = "fishead", .magic = "fishead",
.magicsize = 8, .magicsize = 8,
.header = skeleton_header, .header = skeleton_header,
.nb_header = 0,
}; };
...@@ -122,5 +122,6 @@ const struct ogg_codec ff_speex_codec = { ...@@ -122,5 +122,6 @@ const struct ogg_codec ff_speex_codec = {
.magic = "Speex ", .magic = "Speex ",
.magicsize = 8, .magicsize = 8,
.header = speex_header, .header = speex_header,
.packet = speex_packet .packet = speex_packet,
.nb_header = 2,
}; };
...@@ -150,5 +150,6 @@ const struct ogg_codec ff_theora_codec = { ...@@ -150,5 +150,6 @@ const struct ogg_codec ff_theora_codec = {
.magic = "\200theora", .magic = "\200theora",
.magicsize = 7, .magicsize = 7,
.header = theora_header, .header = theora_header,
.gptopts = theora_gptopts .gptopts = theora_gptopts,
.nb_header = 3,
}; };
...@@ -359,4 +359,5 @@ const struct ogg_codec ff_vorbis_codec = { ...@@ -359,4 +359,5 @@ const struct ogg_codec ff_vorbis_codec = {
.magicsize = 7, .magicsize = 7,
.header = vorbis_header, .header = vorbis_header,
.packet = vorbis_packet, .packet = vorbis_packet,
.nb_header = 3,
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment