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.
Unified · Split
| @@ -915,6 +915,8 @@ static int mov_read_stco(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 914 unmodified lines | ||
| 915 | 915 | |
| 916 | 916 | entries = avio_rb32(pb); |
| 917 | 917 | |
| 918 | + if (!entries) | |
| 919 | + return 0; | |
| 918 | 920 | if (entries >= UINT_MAX/sizeof(int64_t)) |
| 919 | 921 | return -1; |
| 920 | 922 | |
| @@ -1336,6 +1338,8 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 415 unmodified lines | ||
| 1336 | 1338 | |
| 1337 | 1339 | av_dlog(c->fc, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries); |
| 1338 | 1340 | |
| 1341 | + if (!entries) | |
| 1342 | + return 0; | |
| 1339 | 1343 | if (entries >= UINT_MAX / sizeof(*sc->stsc_data)) |
| 1340 | 1344 | return -1; |
| 1341 | 1345 | 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 | ||
| 1451 | 1455 | return -1; |
| 1452 | 1456 | } |
| 1453 | 1457 | |
| 1458 | + if (!entries) | |
| 1459 | + return 0; | |
| 1454 | 1460 | if (entries >= UINT_MAX / sizeof(int) || entries >= (UINT_MAX - 4) / field_size) |
| 1455 | 1461 | return -1; |
| 1456 | 1462 | 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 | ||
| 1550 | 1556 | |
| 1551 | 1557 | av_dlog(c->fc, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries); |
| 1552 | 1558 | |
| 1559 | + if (!entries) | |
| 1560 | + return 0; | |
| 1553 | 1561 | if (entries >= UINT_MAX / sizeof(*sc->ctts_data)) |
| 1554 | 1562 | return -1; |
| 1555 | 1563 | 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 | ||
| 1609 | 1617 | |
| 1610 | 1618 | current_dts -= sc->dts_shift; |
| 1611 | 1619 | |
| 1620 | + if (!sc->sample_count) | |
| 1621 | + return; | |
| 1612 | 1622 | if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries)) |
| 1613 | 1623 | return; |
| 1614 | 1624 | st->index_entries = av_malloc(sc->sample_count*sizeof(*st->index_entries)); |