aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/mov.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-09-11 10:54:41 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-09-11 11:23:40 +0200
commitcbe47b1e8452e37fda592941e7d3f3bb5920c201 (patch)
tree9ea8b6418c4d89e27c98314d41974163b5dbafe8 /libavformat/mov.c
parent64b6279d1414378214a58a55f0066fbc95256c9b (diff)
parentf369b9356c4606cd4d713d60f7db5de119d901fa (diff)
downloadandroid_external_ffmpeg-cbe47b1e8452e37fda592941e7d3f3bb5920c201.tar.gz
android_external_ffmpeg-cbe47b1e8452e37fda592941e7d3f3bb5920c201.tar.bz2
android_external_ffmpeg-cbe47b1e8452e37fda592941e7d3f3bb5920c201.zip
Merge commit 'f369b9356c4606cd4d713d60f7db5de119d901fa'
* commit 'f369b9356c4606cd4d713d60f7db5de119d901fa': avformat: Use av_reallocp_array() where suitable Conflicts: libavformat/asfenc.c libavformat/gxfenc.c libavformat/mov.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/mov.c')
-rw-r--r--libavformat/mov.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c
index fe73493d10..424b8adf30 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2062,7 +2062,6 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
unsigned int stps_index = 0;
unsigned int i, j;
uint64_t stream_size = 0;
- AVIndexEntry *mem;
/* adjust first dts according to edit list */
if ((sc->empty_duration || sc->start_time) && mov->time_scale > 0) {
@@ -2097,10 +2096,12 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
return;
if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries)
return;
- mem = av_realloc(st->index_entries, (st->nb_index_entries + sc->sample_count) * sizeof(*st->index_entries));
- if (!mem)
+ if (av_reallocp_array(&st->index_entries,
+ st->nb_index_entries + sc->sample_count,
+ sizeof(*st->index_entries)) < 0) {
+ st->nb_index_entries = 0;
return;
- st->index_entries = mem;
+ }
st->index_entries_allocated_size = (st->nb_index_entries + sc->sample_count) * sizeof(*st->index_entries);
for (i = 0; i < sc->chunk_count; i++) {
@@ -2207,10 +2208,12 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
av_dlog(mov->fc, "chunk count %d\n", total);
if (total >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries)
return;
- mem = av_realloc(st->index_entries, (st->nb_index_entries + total) * sizeof(*st->index_entries));
- if (!mem)
+ if (av_reallocp_array(&st->index_entries,
+ st->nb_index_entries + total,
+ sizeof(*st->index_entries)) < 0) {
+ st->nb_index_entries = 0;
return;
- st->index_entries = mem;
+ }
st->index_entries_allocated_size = (st->nb_index_entries + total) * sizeof(*st->index_entries);
// populate index
@@ -2581,16 +2584,18 @@ static int mov_read_chap(MOVContext *c, AVIOContext *pb, MOVAtom atom)
static int mov_read_trex(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
MOVTrackExt *trex;
+ int err;
if ((uint64_t)c->trex_count+1 >= UINT_MAX / sizeof(*c->trex_data))
return AVERROR_INVALIDDATA;
- trex = av_realloc(c->trex_data, (c->trex_count+1)*sizeof(*c->trex_data));
- if (!trex)
- return AVERROR(ENOMEM);
+ if ((err = av_reallocp_array(&c->trex_data, c->trex_count + 1,
+ sizeof(*c->trex_data))) < 0) {
+ c->trex_count = 0;
+ return err;
+ }
c->fc->duration = AV_NOPTS_VALUE; // the duration from mvhd is not representing the whole file when fragments are used.
- c->trex_data = trex;
trex = &c->trex_data[c->trex_count++];
avio_r8(pb); /* version */
avio_rb24(pb); /* flags */
@@ -2612,7 +2617,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
int64_t dts;
int data_offset = 0;
unsigned entries, first_sample_flags = frag->flags;
- int flags, distance, i, found_keyframe = 0;
+ int flags, distance, i, found_keyframe = 0, err;
for (i = 0; i < c->fc->nb_streams; i++) {
if (c->fc->streams[i]->id == frag->track_id) {
@@ -2650,12 +2655,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
}
if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data))
return AVERROR_INVALIDDATA;
- ctts_data = av_realloc(sc->ctts_data,
- (entries+sc->ctts_count)*sizeof(*sc->ctts_data));
- if (!ctts_data)
- return AVERROR(ENOMEM);
- sc->ctts_data = ctts_data;
-
+ if ((err = av_reallocp_array(&sc->ctts_data, entries + sc->ctts_count,
+ sizeof(*sc->ctts_data))) < 0) {
+ sc->ctts_count = 0;
+ return err;
+ }
if (flags & MOV_TRUN_DATA_OFFSET) data_offset = avio_rb32(pb);
if (flags & MOV_TRUN_FIRST_SAMPLE_FLAGS) first_sample_flags = avio_rb32(pb);
dts = sc->track_end - sc->time_offset;