diff mbox series

[FFmpeg-devel,6/9] avcodec/libvpxenc: Cleanup on error

Message ID 20240616230831.912377-6-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/9] avcodec/targaenc: Allocate space for the palette | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Michael Niedermayer June 16, 2024, 11:08 p.m. UTC
This or fifo needs to be freed on errors explicitly
I have not verified that its always safe to call vpx_free() this needs to be checked before applying this

Fixes: memleak
Fixes: 68937/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LIBVPX_VP8_fuzzer-4830831016214528

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/libvpxenc.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

James Zern June 17, 2024, 5:10 p.m. UTC | #1
On Sun, Jun 16, 2024 at 4:09 PM Michael Niedermayer
<michael@niedermayer.cc> wrote:
>
> This or fifo needs to be freed on errors explicitly
> I have not verified that its always safe to call vpx_free() this needs to be checked before applying this
>

It should be safe to call into libvpx whether the encoder init
succeeded or not; av_freep() is most of the rest of the code.

> Fixes: memleak
> Fixes: 68937/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LIBVPX_VP8_fuzzer-4830831016214528
>
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/libvpxenc.c | 2 ++
>  1 file changed, 2 insertions(+)
>

lgtm.
Michael Niedermayer June 19, 2024, 10:59 a.m. UTC | #2
On Mon, Jun 17, 2024 at 10:10:38AM -0700, James Zern via ffmpeg-devel wrote:
> On Sun, Jun 16, 2024 at 4:09 PM Michael Niedermayer
> <michael@niedermayer.cc> wrote:
> >
> > This or fifo needs to be freed on errors explicitly
> > I have not verified that its always safe to call vpx_free() this needs to be checked before applying this
> >
> 
> It should be safe to call into libvpx whether the encoder init
> succeeded or not; av_freep() is most of the rest of the code.

Thanks for checking


> 
> > Fixes: memleak
> > Fixes: 68937/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LIBVPX_VP8_fuzzer-4830831016214528
> >
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/libvpxenc.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> 
> lgtm.

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 5c7b6e9de73..5490246d9ed 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -2042,6 +2042,7 @@  const FFCodec ff_libvpx_vp8_encoder = {
     FF_CODEC_ENCODE_CB(vpx_encode),
     .close          = vpx_free,
     .caps_internal  = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
+                      FF_CODEC_CAP_INIT_CLEANUP |
                       FF_CODEC_CAP_AUTO_THREADS,
     .p.pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE },
     .p.priv_class   = &class_vp8,
@@ -2118,6 +2119,7 @@  FFCodec ff_libvpx_vp9_encoder = {
     FF_CODEC_ENCODE_CB(vpx_encode),
     .close          = vpx_free,
     .caps_internal  = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
+                      FF_CODEC_CAP_INIT_CLEANUP |
                       FF_CODEC_CAP_AUTO_THREADS,
     .defaults       = defaults,
     .init_static_data = vp9_init_static,