PR #22893 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22893
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22893.patch

I am not certain that calling     vorbis_block_clear(&s->vb); 
vorbis_dsp_clear(&s->vd); (as we do in libvorbis_encode_close() ) when these 
have only been zero-initialized by us and not initialized by libvorbis as 
happens in certain error paths in libvorbis_encode_init) is correct; therefore 
I have also not added the INIT_CLEANUP flag.


>From 234b9b494a06b67c83fb737a29d8f5d3440f125d Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Wed, 22 Apr 2026 20:46:35 +0200
Subject: [PATCH 1/3] avcodec/libvorbisenc: Fix leak of vorbis_comment upon
 error

Just free it immediately and unconditionally after it is no longer
needed.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/libvorbisenc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index c54ebebae8..540905aa7b 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -291,8 +291,10 @@ static av_cold int libvorbis_encode_init(AVCodecContext 
*avctx)
     if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT))
         vorbis_comment_add_tag(&s->vc, "encoder", LIBAVCODEC_IDENT);
 
-    if ((ret = vorbis_analysis_headerout(&s->vd, &s->vc, &header, &header_comm,
-                                         &header_code))) {
+    ret = vorbis_analysis_headerout(&s->vd, &s->vc, &header, &header_comm,
+                                    &header_code);
+    vorbis_comment_clear(&s->vc);
+    if (ret) {
         ret = vorbis_error_to_averror(ret);
         goto error;
     }
@@ -324,8 +326,6 @@ static av_cold int libvorbis_encode_init(AVCodecContext 
*avctx)
         return ret;
     }
 
-    vorbis_comment_clear(&s->vc);
-
     if ((ret = libvorbis_get_priming_samples(&s->vi, avctx)))
         return ret;
 
-- 
2.52.0


>From 27ab42f7e265022d118478e84aa48e85957af8ba Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Wed, 22 Apr 2026 20:52:21 +0200
Subject: [PATCH 2/3] avcodec/libvorbisenc: Return error upon error

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/libvorbisenc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index 540905aa7b..5ac8bf0fbe 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -323,7 +323,8 @@ static av_cold int libvorbis_encode_init(AVCodecContext 
*avctx)
     s->vp = av_vorbis_parse_init(avctx->extradata, avctx->extradata_size);
     if (!s->vp) {
         av_log(avctx, AV_LOG_ERROR, "invalid extradata\n");
-        return ret;
+        ret = AVERROR_UNKNOWN;
+        goto error;
     }
 
     if ((ret = libvorbis_get_priming_samples(&s->vi, avctx)))
-- 
2.52.0


>From 0eecf799e0bd79ccd96d8297f27222d97d57e43d Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Wed, 22 Apr 2026 20:54:13 +0200
Subject: [PATCH 3/3] avcodec/libvorbisenc: Cleanup on error

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/libvorbisenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index 5ac8bf0fbe..f8bb794a04 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -328,7 +328,7 @@ static av_cold int libvorbis_encode_init(AVCodecContext 
*avctx)
     }
 
     if ((ret = libvorbis_get_priming_samples(&s->vi, avctx)))
-        return ret;
+        goto error;
 
     avctx->frame_size = LIBVORBIS_FRAME_SIZE;
     ff_af_queue_init(avctx, &s->afq);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to