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

Fixes: write into the padding area of the frame

Found-by: Marius Momeu <[email protected]>
Signed-off-by: Michael Niedermayer <[email protected]>


>From b009e72615990ba7e11adbdc1f7351db68714427 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Sat, 2 May 2026 12:22:34 +0200
Subject: [PATCH] avfilter/vf_codecview: Clamp block to the visible frame
 region

Fixes: write into the padding area of the frame

Found-by: Marius Momeu <[email protected]>
Signed-off-by: Michael Niedermayer <[email protected]>
---
 libavfilter/vf_codecview.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_codecview.c b/libavfilter/vf_codecview.c
index a4a701b00c..f20056b91b 100644
--- a/libavfilter/vf_codecview.c
+++ b/libavfilter/vf_codecview.c
@@ -266,9 +266,22 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
             if (par->nb_blocks) {
                 for (int block_idx = 0; block_idx < par->nb_blocks; 
block_idx++) {
                     AVVideoBlockParams *b = av_video_enc_params_block(par, 
block_idx);
-                    uint8_t *buf = frame->data[0] + b->src_y * stride;
 
-                    draw_block_rectangle(buf, b->src_x, b->src_y, b->w, b->h, 
stride, 100);
+                    int64_t x0 = b->src_x;
+                    int64_t y0 = b->src_y;
+                    int64_t x1 = x0 + b->w;
+                    int64_t y1 = y0 + b->h;
+
+                    x0 = FFMAX(x0, 0);
+                    y0 = FFMAX(y0, 0);
+                    x1 = FFMIN(x1, frame->width);
+                    y1 = FFMIN(y1, frame->height);
+
+                    if (x1 <= x0 || y1 <= y0)
+                        continue;
+
+                    uint8_t *buf = frame->data[0] + y0 * stride;
+                    draw_block_rectangle(buf, x0, y0, x1-x0, y1-y0, stride, 
100);
                 }
             }
         }
-- 
2.52.0

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

Reply via email to