Commit 0936e701b4 for ffmpeg
commit 0936e701b4d08ec47d30b6cc67b77c2549172b85
Author: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Date: Tue Nov 10 23:38:24 2026 -0800
avcodec/libx264: size the mb_info map for interlaced encoding
x264 reads mb_info over a row count rounded up to even when interlaced,
so an odd macroblock row count read past the map.
Found during review of #25909 by Forgejo_Fairy.
Signed-off-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index a432c0b50e..e5a853c10a 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -370,7 +370,10 @@ static int setup_mb_info(AVCodecContext *ctx, x264_picture_t *pic,
mbinfo_rects = (const AVVideoRect *)av_video_hint_rects(info);
nb_rects = info->nb_rects;
- mbinfo = av_calloc(mb_width * mb_height, sizeof(*mbinfo));
+ /* x264 rounds the macroblock row count up to an even number for
+ * interlaced and fake-interlaced encoding and reads mb_info over
+ * that grid, so size the map for it. The extra row stays 0. */
+ mbinfo = av_calloc(mb_width * FFALIGN(mb_height, 2), sizeof(*mbinfo));
if (!mbinfo)
return AVERROR(ENOMEM);