Commit da048c6d authored by Michael Niedermayer's avatar Michael Niedermayer

avformat/movenc: Check failure of allocation of ctts_entries and propagate error

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 47785b44
...@@ -1723,6 +1723,8 @@ static int mov_write_ctts_tag(AVIOContext *pb, MOVTrack *track) ...@@ -1723,6 +1723,8 @@ static int mov_write_ctts_tag(AVIOContext *pb, MOVTrack *track)
int i; int i;
ctts_entries = av_malloc_array((track->entry + 1), sizeof(*ctts_entries)); /* worst case */ ctts_entries = av_malloc_array((track->entry + 1), sizeof(*ctts_entries)); /* worst case */
if (!ctts_entries)
return AVERROR(ENOMEM);
ctts_entries[0].count = 1; ctts_entries[0].count = 1;
ctts_entries[0].duration = track->cluster[0].cts; ctts_entries[0].duration = track->cluster[0].cts;
for (i = 1; i < track->entry; i++) { for (i = 1; i < track->entry; i++) {
...@@ -1808,6 +1810,8 @@ static int mov_write_dref_tag(AVIOContext *pb) ...@@ -1808,6 +1810,8 @@ static int mov_write_dref_tag(AVIOContext *pb)
static int mov_write_stbl_tag(AVIOContext *pb, MOVTrack *track) static int mov_write_stbl_tag(AVIOContext *pb, MOVTrack *track)
{ {
int64_t pos = avio_tell(pb); int64_t pos = avio_tell(pb);
int ret;
avio_wb32(pb, 0); /* size */ avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "stbl"); ffio_wfourcc(pb, "stbl");
mov_write_stsd_tag(pb, track); mov_write_stsd_tag(pb, track);
...@@ -1819,8 +1823,11 @@ static int mov_write_stbl_tag(AVIOContext *pb, MOVTrack *track) ...@@ -1819,8 +1823,11 @@ static int mov_write_stbl_tag(AVIOContext *pb, MOVTrack *track)
if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS) if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS)
mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE); mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE);
if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO && if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO &&
track->flags & MOV_TRACK_CTTS && track->entry) track->flags & MOV_TRACK_CTTS && track->entry) {
mov_write_ctts_tag(pb, track);
if ((ret = mov_write_ctts_tag(pb, track)) < 0)
return ret;
}
mov_write_stsc_tag(pb, track); mov_write_stsc_tag(pb, track);
mov_write_stsz_tag(pb, track); mov_write_stsz_tag(pb, track);
mov_write_stco_tag(pb, track); mov_write_stco_tag(pb, track);
...@@ -2028,6 +2035,8 @@ static int mov_write_hmhd_tag(AVIOContext *pb) ...@@ -2028,6 +2035,8 @@ static int mov_write_hmhd_tag(AVIOContext *pb)
static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track) static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track)
{ {
int64_t pos = avio_tell(pb); int64_t pos = avio_tell(pb);
int ret;
avio_wb32(pb, 0); /* size */ avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "minf"); ffio_wfourcc(pb, "minf");
if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO)
...@@ -2048,7 +2057,8 @@ static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track) ...@@ -2048,7 +2057,8 @@ static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track)
if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */ if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
mov_write_hdlr_tag(pb, NULL); mov_write_hdlr_tag(pb, NULL);
mov_write_dinf_tag(pb); mov_write_dinf_tag(pb);
mov_write_stbl_tag(pb, track); if ((ret = mov_write_stbl_tag(pb, track)) < 0)
return ret;
return update_size(pb, pos); return update_size(pb, pos);
} }
...@@ -2095,11 +2105,14 @@ static int mov_write_mdia_tag(AVIOContext *pb, MOVMuxContext *mov, ...@@ -2095,11 +2105,14 @@ static int mov_write_mdia_tag(AVIOContext *pb, MOVMuxContext *mov,
MOVTrack *track) MOVTrack *track)
{ {
int64_t pos = avio_tell(pb); int64_t pos = avio_tell(pb);
int ret;
avio_wb32(pb, 0); /* size */ avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "mdia"); ffio_wfourcc(pb, "mdia");
mov_write_mdhd_tag(pb, mov, track); mov_write_mdhd_tag(pb, mov, track);
mov_write_hdlr_tag(pb, track); mov_write_hdlr_tag(pb, track);
mov_write_minf_tag(pb, track); if ((ret = mov_write_minf_tag(pb, track)) < 0)
return ret;
return update_size(pb, pos); return update_size(pb, pos);
} }
...@@ -2424,6 +2437,8 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov, ...@@ -2424,6 +2437,8 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov,
int64_t pos = avio_tell(pb); int64_t pos = avio_tell(pb);
int entry_backup = track->entry; int entry_backup = track->entry;
int chunk_backup = track->chunkCount; int chunk_backup = track->chunkCount;
int ret;
/* If we want to have an empty moov, but some samples already have been /* If we want to have an empty moov, but some samples already have been
* buffered (delay_moov), pretend that no samples have been written yet. */ * buffered (delay_moov), pretend that no samples have been written yet. */
if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV) if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV)
...@@ -2445,7 +2460,9 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov, ...@@ -2445,7 +2460,9 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov,
if (track->tref_tag) if (track->tref_tag)
mov_write_tref_tag(pb, track); mov_write_tref_tag(pb, track);
mov_write_mdia_tag(pb, mov, track);
if ((ret = mov_write_mdia_tag(pb, mov, track)) < 0)
return ret;
if (track->mode == MODE_PSP) if (track->mode == MODE_PSP)
mov_write_uuid_tag_psp(pb, track); // PSP Movies require this uuid box mov_write_uuid_tag_psp(pb, track); // PSP Movies require this uuid box
if (track->tag == MKTAG('r','t','p',' ')) if (track->tag == MKTAG('r','t','p',' '))
...@@ -3041,7 +3058,9 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov, ...@@ -3041,7 +3058,9 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
mov_write_iods_tag(pb, mov); mov_write_iods_tag(pb, mov);
for (i = 0; i < mov->nb_streams; i++) { for (i = 0; i < mov->nb_streams; i++) {
if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_FRAGMENT) { if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_FRAGMENT) {
mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL); int ret = mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL);
if (ret < 0)
return ret;
} }
} }
if (mov->flags & FF_MOV_FLAG_FRAGMENT) if (mov->flags & FF_MOV_FLAG_FRAGMENT)
...@@ -3879,6 +3898,7 @@ static int mov_flush_fragment(AVFormatContext *s) ...@@ -3879,6 +3898,7 @@ static int mov_flush_fragment(AVFormatContext *s)
MOVMuxContext *mov = s->priv_data; MOVMuxContext *mov = s->priv_data;
int i, first_track = -1; int i, first_track = -1;
int64_t mdat_size = 0; int64_t mdat_size = 0;
int ret;
if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) if (!(mov->flags & FF_MOV_FLAG_FRAGMENT))
return 0; return 0;
...@@ -3901,7 +3921,8 @@ static int mov_flush_fragment(AVFormatContext *s) ...@@ -3901,7 +3921,8 @@ static int mov_flush_fragment(AVFormatContext *s)
if (mov->flags & FF_MOV_FLAG_DELAY_MOOV) if (mov->flags & FF_MOV_FLAG_DELAY_MOOV)
mov_write_identification(s->pb, s); mov_write_identification(s->pb, s);
mov_write_moov_tag(s->pb, mov, s); if ((ret = mov_write_moov_tag(s->pb, mov, s)) < 0)
return ret;
if (mov->flags & FF_MOV_FLAG_DELAY_MOOV) { if (mov->flags & FF_MOV_FLAG_DELAY_MOOV) {
if (mov->flags & FF_MOV_FLAG_FASTSTART) if (mov->flags & FF_MOV_FLAG_FASTSTART)
...@@ -4949,7 +4970,8 @@ static int mov_write_header(AVFormatContext *s) ...@@ -4949,7 +4970,8 @@ static int mov_write_header(AVFormatContext *s)
if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV && if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV &&
!(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) { !(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) {
mov_write_moov_tag(pb, mov, s); if ((ret = mov_write_moov_tag(pb, mov, s)) < 0)
return ret;
mov->fragments++; mov->fragments++;
if (mov->flags & FF_MOV_FLAG_FASTSTART) if (mov->flags & FF_MOV_FLAG_FASTSTART)
mov->reserved_moov_pos = avio_tell(pb); mov->reserved_moov_pos = avio_tell(pb);
...@@ -4969,7 +4991,8 @@ static int get_moov_size(AVFormatContext *s) ...@@ -4969,7 +4991,8 @@ static int get_moov_size(AVFormatContext *s)
if ((ret = ffio_open_null_buf(&moov_buf)) < 0) if ((ret = ffio_open_null_buf(&moov_buf)) < 0)
return ret; return ret;
mov_write_moov_tag(moov_buf, mov, s); if ((ret = mov_write_moov_tag(moov_buf, mov, s)) < 0)
return ret;
return ffio_close_null_buf(moov_buf); return ffio_close_null_buf(moov_buf);
} }
...@@ -5152,11 +5175,13 @@ static int mov_write_trailer(AVFormatContext *s) ...@@ -5152,11 +5175,13 @@ static int mov_write_trailer(AVFormatContext *s)
res = shift_data(s); res = shift_data(s);
if (res == 0) { if (res == 0) {
avio_seek(pb, mov->reserved_moov_pos, SEEK_SET); avio_seek(pb, mov->reserved_moov_pos, SEEK_SET);
mov_write_moov_tag(pb, mov, s); if ((res = mov_write_moov_tag(pb, mov, s)) < 0)
goto error;
} }
} else if (mov->reserved_moov_size > 0) { } else if (mov->reserved_moov_size > 0) {
int64_t size; int64_t size;
mov_write_moov_tag(pb, mov, s); if ((res = mov_write_moov_tag(pb, mov, s)) < 0)
goto error;
size = mov->reserved_moov_size - (avio_tell(pb) - mov->reserved_moov_pos); size = mov->reserved_moov_size - (avio_tell(pb) - mov->reserved_moov_pos);
if (size < 8){ if (size < 8){
av_log(s, AV_LOG_ERROR, "reserved_moov_size is too small, needed %"PRId64" additional\n", 8-size); av_log(s, AV_LOG_ERROR, "reserved_moov_size is too small, needed %"PRId64" additional\n", 8-size);
...@@ -5168,8 +5193,10 @@ static int mov_write_trailer(AVFormatContext *s) ...@@ -5168,8 +5193,10 @@ static int mov_write_trailer(AVFormatContext *s)
ffio_fill(pb, 0, size - 8); ffio_fill(pb, 0, size - 8);
avio_seek(pb, moov_pos, SEEK_SET); avio_seek(pb, moov_pos, SEEK_SET);
} else { } else {
mov_write_moov_tag(pb, mov, s); if ((res = mov_write_moov_tag(pb, mov, s)) < 0)
goto error;
} }
res = 0;
} else { } else {
mov_auto_flush_fragment(s); mov_auto_flush_fragment(s);
for (i = 0; i < mov->nb_streams; i++) for (i = 0; i < mov->nb_streams; i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment