aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/mov.c
diff options
context:
space:
mode:
authorAlexandra Khirnova <alexandra.khirnova@gmail.com>2013-09-10 11:57:35 +0200
committerDiego Biurrun <diego@biurrun.de>2013-09-10 12:38:32 +0200
commitf369b9356c4606cd4d713d60f7db5de119d901fa (patch)
tree174e199dd9716a32fbee4fb235d3938721fb333f /libavformat/mov.c
parentbdf990425e2be6912a6d29f032ca558448c8635a (diff)
downloadffmpeg-f369b9356c4606cd4d713d60f7db5de119d901fa.tar.gz
avformat: Use av_reallocp_array() where suitable
Signed-off-by: Diego Biurrun <diego@biurrun.de>
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 6614f89394..9c72426539 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1841,7 +1841,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->time_offset && mov->time_scale > 0) {
@@ -1875,10 +1874,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++) {
@@ -1973,10 +1974,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
@@ -2307,13 +2310,15 @@ 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);
- c->trex_data = trex;
+ if ((err = av_reallocp_array(&c->trex_data, c->trex_count + 1,
+ sizeof(*c->trex_data))) < 0) {
+ c->trex_count = 0;
+ return err;
+ }
trex = &c->trex_data[c->trex_count++];
avio_r8(pb); /* version */
avio_rb24(pb); /* flags */
@@ -2335,7 +2340,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) {
@@ -2373,12 +2378,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;