diff mbox series

[FFmpeg-devel,1/4] avformat/audiointerleave: Check before dereferencing

Message ID 20200126102739.26495-1-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/4] avformat/audiointerleave: Check before dereferencing | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 26, 2020, 10:27 a.m. UTC
In order to use ff_audio_rechunk_interleave() (a special interleavement
function for situations where the ordinary "interleave by dts" is not
appropriate), the AVStreams must have private data and this private data
must begin with an AudioInterleaveContext which contains a fifo that may
need to be freed and when ff_audio_interleave_close() was called, it just
assumed that everything has been properly set up, i.e. that every streams
priv_data exists. This implies that this function can not be called from
the deinit function of a muxer, because such functions might be called
if the private data has not been successfully allocated. In order to
change this, add a check for whether the private data exists before
trying to free the fifo in it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/audiointerleave.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Paul B Mahol Jan. 26, 2020, 10:38 a.m. UTC | #1
lgtm

On 1/26/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> In order to use ff_audio_rechunk_interleave() (a special interleavement
> function for situations where the ordinary "interleave by dts" is not
> appropriate), the AVStreams must have private data and this private data
> must begin with an AudioInterleaveContext which contains a fifo that may
> need to be freed and when ff_audio_interleave_close() was called, it just
> assumed that everything has been properly set up, i.e. that every streams
> priv_data exists. This implies that this function can not be called from
> the deinit function of a muxer, because such functions might be called
> if the private data has not been successfully allocated. In order to
> change this, add a check for whether the private data exists before
> trying to free the fifo in it.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/audiointerleave.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
> index b602eb7105..6797546a44 100644
> --- a/libavformat/audiointerleave.c
> +++ b/libavformat/audiointerleave.c
> @@ -33,7 +33,7 @@ void ff_audio_interleave_close(AVFormatContext *s)
>          AVStream *st = s->streams[i];
>          AudioInterleaveContext *aic = st->priv_data;
>
> -        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
> +        if (aic && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
>              av_fifo_freep(&aic->fifo);
>      }
>  }
> --
> 2.20.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer Jan. 26, 2020, 4:26 p.m. UTC | #2
On Sun, Jan 26, 2020 at 11:38:17AM +0100, Paul B Mahol wrote:
> lgtm

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
index b602eb7105..6797546a44 100644
--- a/libavformat/audiointerleave.c
+++ b/libavformat/audiointerleave.c
@@ -33,7 +33,7 @@  void ff_audio_interleave_close(AVFormatContext *s)
         AVStream *st = s->streams[i];
         AudioInterleaveContext *aic = st->priv_data;
 
-        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
+        if (aic && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
             av_fifo_freep(&aic->fifo);
     }
 }