[FFmpeg-devel] [PATCH 12/19] avcodec/mpegvideo_enc: Don't segfault on unorthodox mpeg_quant

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Apr 7 00:55:09 EEST 2021


The (deprecated) field AVCodecContext.mpeg_quant has no range
restriction; MpegEncContext.mpeg_quant is restricted to 0..1.
If the former is set, the latter is overwritten with it without
checking the range. This can trigger an av_assert2() with the MPEG-4
encoder when writing said field.

Fix this by just setting MpegEncContext.mpeg_quant to 1 if
AVCodecContext.mpeg_quant is set.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
This can not be triggered if one only sets options via the dictionary in
avcodec_open2(); one needs to set it directly in the AVCodecContext or
use the private class of AVCodecContext.

 libavcodec/mpegvideo_enc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index d1f2460409..0a1d0db86d 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -564,7 +564,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 #if FF_API_PRIVATE_OPT
     FF_DISABLE_DEPRECATION_WARNINGS
     if (avctx->mpeg_quant)
-        s->mpeg_quant = avctx->mpeg_quant;
+        s->mpeg_quant = 1;
     FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
-- 
2.27.0



More information about the ffmpeg-devel mailing list