History

mov: Don't av_malloc(0).

malloc() is allowed to return NULL when zero is the argument. This causes us to think malloc has failed and return AVERROR(ENOMEM). In addition OS X malloc() returns an unfreeable non-NULL pointer for size zero when alignment is greater than 16.

Alex Converse committed 14 years ago

Commit 52401b81 parent 9179f271 file · +10 −0Browse files

Unified · Split

libavformat/mov.c+10−0
@@ -915,6 +915,8 @@ static int mov_read_stco(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 914 unmodified lines
915915
916916 entries = avio_rb32(pb);
917917
918+ if (!entries)
919+ return 0;
918920 if (entries >= UINT_MAX/sizeof(int64_t))
919921 return -1;
920922
@@ -1336,6 +1338,8 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 415 unmodified lines
13361338
13371339 av_dlog(c->fc, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);
13381340
1341+ if (!entries)
1342+ return 0;
13391343 if (entries >= UINT_MAX / sizeof(*sc->stsc_data))
13401344 return -1;
13411345 sc->stsc_data = av_malloc(entries * sizeof(*sc->stsc_data));
@@ -1451,6 +1455,8 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 109 unmodified lines
14511455 return -1;
14521456 }
14531457
1458+ if (!entries)
1459+ return 0;
14541460 if (entries >= UINT_MAX / sizeof(int) || entries >= (UINT_MAX - 4) / field_size)
14551461 return -1;
14561462 sc->sample_sizes = av_malloc(entries * sizeof(int));
@@ -1550,6 +1556,8 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 93 unmodified lines
15501556
15511557 av_dlog(c->fc, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries);
15521558
1559+ if (!entries)
1560+ return 0;
15531561 if (entries >= UINT_MAX / sizeof(*sc->ctts_data))
15541562 return -1;
15551563 sc->ctts_data = av_malloc(entries * sizeof(*sc->ctts_data));
@@ -1609,6 +1617,8 @@ static void mov_build_index(MOVContext *mov, AVStream *st) · 53 unmodified lines
16091617
16101618 current_dts -= sc->dts_shift;
16111619
1620+ if (!sc->sample_count)
1621+ return;
16121622 if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries))
16131623 return;
16141624 st->index_entries = av_malloc(sc->sample_count*sizeof(*st->index_entries));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t