st = c->fc->streams[c->fc->nb_streams-1];
st->codecpar->sample_rate = get_bits_long(&gb, 32);
+ if (st->codecpar->sample_rate <= 0) {
+ av_log(c->fc, AV_LOG_ERROR, "Invalid sample rate %d\n", st->codecpar->sample_rate);
+ return AVERROR_INVALIDDATA;
+ }
skip_bits_long(&gb, 32); /* max bitrate */
st->codecpar->bit_rate = get_bits_long(&gb, 32);
st->codecpar->bits_per_coded_sample = get_bits(&gb, 8);
mov_metadata_creation_time(&st->metadata, creation_time);
sc->time_scale = avio_rb32(pb);
+ if (sc->time_scale <= 0) {
+ av_log(c->fc, AV_LOG_ERROR, "Invalid mdhd time scale %d\n", sc->time_scale);
+ return AVERROR_INVALIDDATA;
+ }
st->duration = (version == 1) ? avio_rb64(pb) : avio_rb32(pb); /* duration */
lang = avio_rb16(pb); /* language */
}
mov_metadata_creation_time(&c->fc->metadata, creation_time);
c->time_scale = avio_rb32(pb); /* time scale */
-
+ if (c->time_scale <= 0) {
+ av_log(c->fc, AV_LOG_ERROR, "Invalid mvhd time scale %d\n", c->time_scale);
+ return AVERROR_INVALIDDATA;
+ }
av_log(c->fc, AV_LOG_TRACE, "time scale = %i\n", c->time_scale);
c->duration = (version == 1) ? avio_rb64(pb) : avio_rb32(pb); /* duration */
static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb,
AVStream *st, MOVStreamContext *sc)
{
- uint8_t codec_name[32];
+ uint8_t codec_name[32] = { 0 };
int64_t stsd_start;
unsigned int len;
(codec_tag != format &&
// prores is allowed to have differing data format and codec tag
codec_tag != AV_RL32("apcn") && codec_tag != AV_RL32("apch") &&
+ // so is dv (sigh)
+ codec_tag != AV_RL32("dvpp") && codec_tag != AV_RL32("dvcp") &&
(c->fc->video_codec_id ? video_codec_id != c->fc->video_codec_id
: codec_tag != MKTAG('j','p','e','g')))) {
/* Multiple fourcc, we skip JPEG. This is not correct, we should
} else if (st->codecpar->codec_type==AVMEDIA_TYPE_AUDIO) {
st->codecpar->codec_id = id;
mov_parse_stsd_audio(c, pb, st, sc);
+ if (st->codecpar->sample_rate < 0) {
+ av_log(c->fc, AV_LOG_ERROR, "Invalid sample rate %d\n", st->codecpar->sample_rate);
+ return AVERROR_INVALIDDATA;
+ }
} else if (st->codecpar->codec_type==AVMEDIA_TYPE_SUBTITLE){
st->codecpar->codec_id = id;
mov_parse_stsd_subtitle(c, pb, st, sc,
}
/**
- * Find the closest previous keyframe to the timestamp, in e_old index
- * entries.
+ * Find the closest previous frame to the timestamp, in e_old index
+ * entries. Searching for just any frame / just key frames can be controlled by
+ * last argument 'flag'.
* Returns the index of the entry in st->index_entries if successful,
* else returns -1.
*/
-static int64_t find_prev_closest_keyframe_index(AVStream *st,
- AVIndexEntry *e_old,
- int nb_old,
- int64_t timestamp,
- int flag)
+static int64_t find_prev_closest_index(AVStream *st,
+ AVIndexEntry *e_old,
+ int nb_old,
+ int64_t timestamp,
+ int flag)
{
AVIndexEntry *e_keep = st->index_entries;
int nb_keep = st->nb_index_entries;
search_timestamp = FFMAX(search_timestamp - msc->time_scale, e_old[0].timestamp);
}
- index = find_prev_closest_keyframe_index(st, e_old, nb_old, search_timestamp, 0);
+ index = find_prev_closest_index(st, e_old, nb_old, search_timestamp, 0);
if (index == -1) {
- av_log(mov->fc, AV_LOG_ERROR, "Missing key frame while reordering index according to edit list\n");
- continue;
+ av_log(mov->fc, AV_LOG_WARNING,
+ "st: %d edit list: %"PRId64" Missing key frame while searching for timestamp: %"PRId64"\n",
+ st->index, edit_list_index, search_timestamp);
+ index = find_prev_closest_index(st, e_old, nb_old, search_timestamp, AVSEEK_FLAG_ANY);
+
+ if (index == -1) {
+ av_log(mov->fc, AV_LOG_WARNING,
+ "st: %d edit list %"PRId64" Cannot find an index entry before timestamp: %"PRId64".\n"
+ "Rounding edit list media time to zero.\n",
+ st->index, edit_list_index, search_timestamp);
+ index = 0;
+ edit_list_media_time = 0;
+ }
}
current = e_old + index;
timescale = av_make_q(1, avio_rb32(pb));
+ if (timescale.den <= 0) {
+ av_log(c->fc, AV_LOG_ERROR, "Invalid sidx timescale 1/%d\n", timescale.den);
+ return AVERROR_INVALIDDATA;
+ }
+
if (version == 0) {
pts = avio_rb32(pb);
offset += avio_rb32(pb);
}
e->rate = avio_rb32(pb) / 65536.0;
av_log(c->fc, AV_LOG_TRACE, "duration=%"PRId64" time=%"PRId64" rate=%f\n",
- e->duration, e->time, e->rate);
+ e->duration, e->time, e->rate);
+
+ if (e->time < 0 && e->time != -1 &&
+ c->fc->strict_std_compliance >= FF_COMPLIANCE_STRICT) {
+ av_log(c->fc, AV_LOG_ERROR, "Track %d, edit %d: Invalid edit list media time=%"PRId64"\n",
+ c->fc->nb_streams-1, i, e->time);
+ return AVERROR_INVALIDDATA;
+ }
}
sc->elst_count = i;