diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-08-05 09:57:07 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-08-05 09:57:28 +0200 |
commit | dd98d9d1ff88b5dcd413e8d5359aaaf478de32e5 (patch) | |
tree | c65fb88e1c4a0488f95577500cba268959251023 /libavformat | |
parent | d6c36fba0be8aaa7ba3f15f8a2a7b872817200f3 (diff) | |
parent | 7684a36113fa12c88ba80b5498f05849a6b58632 (diff) | |
download | ffmpeg-dd98d9d1ff88b5dcd413e8d5359aaaf478de32e5.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
mxfenc: switch to av_reallocp_array() and check allocation errors
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/mxfenc.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index b3ab1733ed..52cb2826b8 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -1300,7 +1300,7 @@ static void mxf_write_klv_fill(AVFormatContext *s) } } -static void mxf_write_partition(AVFormatContext *s, int bodysid, +static int mxf_write_partition(AVFormatContext *s, int bodysid, int indexsid, const uint8_t *key, int write_metadata) { @@ -1309,6 +1309,7 @@ static void mxf_write_partition(AVFormatContext *s, int bodysid, int64_t header_byte_count_offset; unsigned index_byte_count = 0; uint64_t partition_offset = avio_tell(pb); + int err; if (!mxf->edit_unit_byte_count && mxf->edit_units_count) index_byte_count = 85 + 12+(s->nb_streams+1)*6 + @@ -1323,10 +1324,11 @@ static void mxf_write_partition(AVFormatContext *s, int bodysid, } if (!memcmp(key, body_partition_key, 16)) { - mxf->body_partition_offset = - av_realloc(mxf->body_partition_offset, - (mxf->body_partitions_count+1)* - sizeof(*mxf->body_partition_offset)); + if ((err = av_reallocp_array(&mxf->body_partition_offset, mxf->body_partitions_count + 1, + sizeof(*mxf->body_partition_offset))) < 0) { + mxf->body_partitions_count = 0; + return err; + } mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset; } @@ -1391,6 +1393,8 @@ static void mxf_write_partition(AVFormatContext *s, int bodysid, } avio_flush(pb); + + return 0; } static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, @@ -1917,13 +1921,14 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) AVStream *st = s->streams[pkt->stream_index]; MXFStreamContext *sc = st->priv_data; MXFIndexEntry ie = {0}; + int err; if (!mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) { - mxf->index_entries = av_realloc(mxf->index_entries, - (mxf->edit_units_count + EDIT_UNITS_PER_BODY)*sizeof(*mxf->index_entries)); - if (!mxf->index_entries) { + if ((err = av_reallocp_array(&mxf->index_entries, mxf->edit_units_count + + EDIT_UNITS_PER_BODY, sizeof(*mxf->index_entries))) < 0) { + mxf->edit_units_count = 0; av_log(s, AV_LOG_ERROR, "could not allocate index entries\n"); - return -1; + return err; } } @@ -1946,11 +1951,13 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) if (!mxf->header_written) { if (mxf->edit_unit_byte_count) { - mxf_write_partition(s, 1, 2, header_open_partition_key, 1); + if ((err = mxf_write_partition(s, 1, 2, header_open_partition_key, 1)) < 0) + return err; mxf_write_klv_fill(s); mxf_write_index_table_segment(s); } else { - mxf_write_partition(s, 0, 0, header_open_partition_key, 1); + if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0) + return err; } mxf->header_written = 1; } @@ -1960,8 +1967,8 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) (!mxf->edit_units_count || mxf->edit_units_count > EDIT_UNITS_PER_BODY) && !(ie.flags & 0x33)) { // I frame, Gop start mxf_write_klv_fill(s); - mxf_write_partition(s, 1, 2, body_partition_key, 0); - + if ((err = mxf_write_partition(s, 1, 2, body_partition_key, 0)) < 0) + return err; mxf_write_klv_fill(s); mxf_write_index_table_segment(s); } @@ -2030,16 +2037,18 @@ static int mxf_write_footer(AVFormatContext *s) { MXFContext *mxf = s->priv_data; AVIOContext *pb = s->pb; + int err; mxf->duration = mxf->last_indexed_edit_unit + mxf->edit_units_count; mxf_write_klv_fill(s); mxf->footer_partition_offset = avio_tell(pb); if (mxf->edit_unit_byte_count) { // no need to repeat index - mxf_write_partition(s, 0, 0, footer_partition_key, 0); + if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 0)) < 0) + return err; } else { - mxf_write_partition(s, 0, 2, footer_partition_key, 0); - + if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0) + return err; mxf_write_klv_fill(s); mxf_write_index_table_segment(s); } @@ -2050,11 +2059,13 @@ static int mxf_write_footer(AVFormatContext *s) if (s->pb->seekable) { avio_seek(pb, 0, SEEK_SET); if (mxf->edit_unit_byte_count) { - mxf_write_partition(s, 1, 2, header_closed_partition_key, 1); + if ((err = mxf_write_partition(s, 1, 2, header_closed_partition_key, 1)) < 0) + return err; mxf_write_klv_fill(s); mxf_write_index_table_segment(s); } else { - mxf_write_partition(s, 0, 0, header_closed_partition_key, 1); + if ((err = mxf_write_partition(s, 0, 0, header_closed_partition_key, 1)) < 0) + return err; } } |