return 0;
n_hmmt = avio_rb32(pb);
+ if (n_hmmt > len / 4)
+ return AVERROR_INVALIDDATA;
for (i = 0; i < n_hmmt && !pb->eof_reached; i++) {
int moment_time = avio_rb32(pb);
avpriv_new_chapter(c->fc, i, av_make_q(1, 1000), moment_time, AV_NOPTS_VALUE, NULL);
if (tmcd_ctx->tmcd_flags & 0x0008) {
int timescale = AV_RB32(st->codecpar->extradata + 8);
int framedur = AV_RB32(st->codecpar->extradata + 12);
- st->avg_frame_rate.num *= timescale;
- st->avg_frame_rate.den *= framedur;
+ st->avg_frame_rate = av_mul_q(st->avg_frame_rate, (AVRational){timescale, framedur});
#if FF_API_LAVF_AVCTX
FF_DISABLE_DEPRECATION_WARNINGS
- st->codec->time_base.den *= timescale;
- st->codec->time_base.num *= framedur;
+ st->codec->time_base = av_mul_q(st->codec->time_base , (AVRational){framedur, timescale});
FF_ENABLE_DEPRECATION_WARNINGS
#endif
}
entries = avio_rb32(pb);
/* Each entry contains a size (4 bytes) and format (4 bytes). */
- if (entries <= 0 || entries > atom.size / 8) {
+ if (entries <= 0 || entries > atom.size / 8 || entries > 1024) {
av_log(c->fc, AV_LOG_ERROR, "invalid STSD entries %d\n", entries);
return AVERROR_INVALIDDATA;
}
av_log(c->fc, AV_LOG_ERROR, "Empty stereoscopic video box\n");
return AVERROR_INVALIDDATA;
}
+
+ if (sc->stereo3d)
+ return AVERROR_INVALIDDATA;
+
avio_skip(pb, 4); /* version + flags */
mode = avio_r8(pb);
c->atom_depth --;
return err;
}
- if (c->found_moov && c->found_mdat &&
+ if (c->found_moov && c->found_mdat && a.size <= INT64_MAX - start_pos &&
((!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & AVFMT_FLAG_IGNIDX || c->frag_index.complete) ||
start_pos + a.size == avio_size(pb))) {
if (!(pb->seekable & AVIO_SEEKABLE_NORMAL) || c->fc->flags & AVFMT_FLAG_IGNIDX || c->frag_index.complete)
/* check file header */
offset = 0;
for (;;) {
+ int64_t size;
+ int minsize = 8;
/* ignore invalid offset */
if ((offset + 8) > (unsigned int)p->buf_size)
break;
+ size = AV_RB32(p->buf + offset);
+ if (size == 1 && offset + 16 > (unsigned int)p->buf_size) {
+ size = AV_RB64(p->buf+offset + 8);
+ minsize = 16;
+ } else if (size == 0) {
+ size = p->buf_size - offset;
+ }
+ if (size < minsize) {
+ offset += 4;
+ continue;
+ }
tag = AV_RL32(p->buf + offset + 4);
switch(tag) {
/* check for obvious tags */
case MKTAG('p','n','o','t'): /* detect movs with preview pics like ew.mov and april.mov */
case MKTAG('u','d','t','a'): /* Packet Video PVAuthor adds this and a lot of more junk */
case MKTAG('f','t','y','p'):
- if (AV_RB32(p->buf+offset) < 8 &&
- (AV_RB32(p->buf+offset) != 1 ||
- offset + 12 > (unsigned int)p->buf_size ||
- AV_RB64(p->buf+offset + 8) == 0)) {
- score = FFMAX(score, AVPROBE_SCORE_EXTENSION);
- } else if (tag == MKTAG('f','t','y','p') &&
+ if (tag == MKTAG('f','t','y','p') &&
( AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' ')
|| AV_RL32(p->buf + offset + 8) == MKTAG('j','p','x',' ')
)) {
} else {
score = AVPROBE_SCORE_MAX;
}
- offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset;
break;
/* those are more common words, so rate then a bit less */
case MKTAG('e','d','i','w'): /* xdcam files have reverted first tags */
case MKTAG('j','u','n','k'):
case MKTAG('p','i','c','t'):
score = FFMAX(score, AVPROBE_SCORE_MAX - 5);
- offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset;
break;
case MKTAG(0x82,0x82,0x7f,0x7d):
case MKTAG('s','k','i','p'):
case MKTAG('p','r','f','l'):
/* if we only find those cause probedata is too small at least rate them */
score = FFMAX(score, AVPROBE_SCORE_EXTENSION);
- offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset;
break;
- default:
- offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset;
}
+ offset += size;
}
if (score > AVPROBE_SCORE_MAX - 50 && moov_offset != -1) {
/* moov atom in the header - we should make sure that this is not a
return sample;
}
+static int64_t mov_get_skip_samples(AVStream *st, int sample)
+{
+ MOVStreamContext *sc = st->priv_data;
+ int64_t first_ts = st->internal->index_entries[0].timestamp;
+ int64_t ts = st->internal->index_entries[sample].timestamp;
+ int64_t off;
+
+ if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)
+ return 0;
+
+ /* compute skip samples according to stream start_pad, seek ts and first ts */
+ off = av_rescale_q(ts - first_ts, st->time_base,
+ (AVRational){1, st->codecpar->sample_rate});
+ return FFMAX(sc->start_pad - off, 0);
+}
+
static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
{
MOVContext *mc = s->priv_data;
if (mc->seek_individually) {
/* adjust seek timestamp to found sample timestamp */
int64_t seek_timestamp = st->internal->index_entries[sample].timestamp;
+ st->internal->skip_samples = mov_get_skip_samples(st, sample);
for (i = 0; i < s->nb_streams; i++) {
int64_t timestamp;
- MOVStreamContext *sc = s->streams[i]->priv_data;
st = s->streams[i];
- st->internal->skip_samples = (sample_time <= 0) ? sc->start_pad : 0;
if (stream_index == i)
continue;
timestamp = av_rescale_q(seek_timestamp, s->streams[stream_index]->time_base, st->time_base);
- mov_seek_stream(s, st, timestamp, flags);
+ sample = mov_seek_stream(s, st, timestamp, flags);
+ if (sample >= 0)
+ st->internal->skip_samples = mov_get_skip_samples(st, sample);
}
} else {
for (i = 0; i < s->nb_streams; i++) {