PR #23841 opened by Raja-89
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23841
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23841.patch

When frames in a batch have different resolutions, the pre-allocated contiguous 
buffer (sized for the first frame) would cause data corruption or buffer 
overrun.

Detect dimension mismatch inside the batching loop: if a frame's height or 
width differs from the first frame, push it back to the front of the lltask 
queue and end the current batch early. The mismatched frame becomes the first 
frame of the next batch.

Signed-off-by: Raja Rathour 



>From e64b5a3476f48fac15a025ce6ff833909504bca9 Mon Sep 17 00:00:00 2001
From: Raja-89 <[email protected]>
Date: Sat, 18 Jul 2026 20:06:22 +0530
Subject: [PATCH] avfilter/dnn: handle resolution change mid-batch in Torch
 backend

When frames in a batch have different resolutions, the pre-allocated
contiguous buffer (sized for the first frame) would cause data
corruption or buffer overrun.

Detect dimension mismatch inside the batching loop: if a frame's
height or width differs from the first frame, push it back to the
front of the lltask queue and end the current batch early. The
mismatched frame becomes the first frame of the next batch.

Signed-off-by: Raja Rathour <[email protected]>
---
 libavfilter/dnn/dnn_backend_torch.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavfilter/dnn/dnn_backend_torch.cpp 
b/libavfilter/dnn/dnn_backend_torch.cpp
index 9ba6d61377..c7fa0bcbb3 100644
--- a/libavfilter/dnn/dnn_backend_torch.cpp
+++ b/libavfilter/dnn/dnn_backend_torch.cpp
@@ -202,9 +202,15 @@ static int fill_model_input_th(THModel *th_model, 
THRequestItem *request)
         if (!lltask)
             break;
 
+        task = lltask->task;
+        if (task->in_frame->height != input.dims[height_idx] ||
+            task->in_frame->width  != input.dims[width_idx]) {
+            ff_queue_push_front(th_model->lltask_queue, lltask);
+            break;
+        }
+
         request->lltasks[i] = lltask;
         request->lltask_count = i + 1;
-        task = lltask->task;
 
         input.data = batch_data + i * frame_size;
 
-- 
2.52.0

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

Reply via email to