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

AVAILABLE(cand_up_right, B0) reads the motion field at B0 before the
xB0 < width test. cand_up_right_sap is not limited to the picture
width, so at the right edge of a picture whose width is not a multiple
of the CTB size this reads the first entry of the next row, and the
result is then discarded. The read stays inside tab_mvf (PU offsets are
multiples of the minimum PU size, so the row is never the last one),
but there is no reason to make it.

Test the width first in the merge and the AMVP derivation. The result
of the condition is unchanged.

Discovered and written by AI


>From 0dab1a75b9558aa4b7de09fb82b3c2bd198c9d9e Mon Sep 17 00:00:00 2001
From: Kieran Kunhya <[email protected]>
Date: Mon, 2 Nov 2026 23:04:26 +0100
Subject: [PATCH] avcodec/hevc/mvs: test xB0 against the width before reading
 B0

AVAILABLE(cand_up_right, B0) reads the motion field at B0 before the
xB0 < width test. cand_up_right_sap is not limited to the picture
width, so at the right edge of a picture whose width is not a multiple
of the CTB size this reads the first entry of the next row, and the
result is then discarded. The read stays inside tab_mvf (PU offsets are
multiples of the minimum PU size, so the row is never the last one),
but there is no reason to make it.

Test the width first in the merge and the AMVP derivation. The result
of the condition is unchanged.
---
 libavcodec/hevc/mvs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/hevc/mvs.c b/libavcodec/hevc/mvs.c
index 937c7cf753e..a14cfc6f804 100644
--- a/libavcodec/hevc/mvs.c
+++ b/libavcodec/hevc/mvs.c
@@ -368,8 +368,8 @@ static void 
derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCCont
     }
 
     // above right spatial merge candidate
-    is_available_b0 = AVAILABLE(cand_up_right, B0) &&
-                      xB0 < sps->width &&
+    is_available_b0 = xB0 < sps->width &&
+                      AVAILABLE(cand_up_right, B0) &&
                       PRED_BLOCK_AVAILABLE(B0) &&
                       !is_diff_mer(pps, xB0, yB0, x0, y0);
 
@@ -689,8 +689,8 @@ b_candidates:
     xB0    = x0 + nPbW;
     yB0    = y0 - 1;
 
-    is_available_b0 =  AVAILABLE(cand_up_right, B0) &&
-                       xB0 < sps->width &&
+    is_available_b0 =  xB0 < sps->width &&
+                       AVAILABLE(cand_up_right, B0) &&
                        PRED_BLOCK_AVAILABLE(B0);
 
     // above spatial merge candidate
-- 
2.54.0

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

Reply via email to