[FFmpeg-devel] [PATCH] mxfenc: ensure mxf->body_partition_offset is not NULL before using it

Mark Reid mindmark at gmail.com
Sat Mar 14 02:17:18 CET 2015


On Fri, Mar 13, 2015 at 6:02 AM, Andreas Cadhalpun <
andreas.cadhalpun at googlemail.com> wrote:

> On 13.03.2015 11:59, Tomas Härdin wrote:
> > On Thu, 2015-03-12 at 17:48 +0100, Andreas Cadhalpun wrote:
> >> This fixes a crash, when trying to mux h264 into mxf_opatom.
> >>
> >> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com>
> >> ---
> >>  libavformat/mxfenc.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
> >> index 898951c..2891f5d 100644
> >> --- a/libavformat/mxfenc.c
> >> +++ b/libavformat/mxfenc.c
> >> @@ -2358,7 +2358,7 @@ static int mxf_write_footer(AVFormatContext *s)
> >>      mxf_write_random_index_pack(s);
> >>
> >>      if (s->pb->seekable) {
> >> -        if (s->oformat == &ff_mxf_opatom_muxer){
> >> +        if (s->oformat == &ff_mxf_opatom_muxer &&
> mxf->body_partition_offset){
> >>              /* rewrite body partition to update lengths */
> >>              avio_seek(pb, mxf->body_partition_offset[0], SEEK_SET);
> >>              if ((err = mxf_write_opatom_body_partition(s)) < 0)
> >
> > Doesn't this need to happen for H.264 as well?
>
> Maybe, but the seek can't work if mxf->body_partition_offset is NULL.
> Would it be better to add the check only around the seek?
>
> > A better solution would
> > be to figure out why mxf->body_partition_offset becomes NULL so that
> > index tables and such can be rewritten properly.
>
> It can always happen that mxf->body_partition_offset is NULL, e.g. if
> no memory is left, or if something else fails. Try e.g.:
> ffmpeg -f lavfi -i testsrc -c:v libx264 -f mxf_opatom
>
>
mxf->body_partition_offset is NULL because currently only AVC Intra 50/100
h264 is supported. The encoder figures out the h264 format by parsing the
h264 packet and doesn't write the body partiton (or even the header
partition) untill after it parses the first packet. If the packet is
invalid, nothing get written and mxf->body_partition_offset doesn't get
allocated.  perhaps mxf_write_footer should return a error if
mxf->body_partition_offset is NULL or just if mxf->header_written == 0
 before doing trying to write anything.


More information about the ffmpeg-devel mailing list