Commit 2e1da88de8 for ffmpeg
commit 2e1da88de8ba05c1f6b29047492a20dbcaebb634
Author: Kieran Kunhya <kierank@obe.tv>
Date: Mon Nov 2 23:04:26 2026 +0100
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.
diff --git a/libavcodec/hevc/mvs.c b/libavcodec/hevc/mvs.c
index b22b3e7ac6..854c6f8bad 100644
--- a/libavcodec/hevc/mvs.c
+++ b/libavcodec/hevc/mvs.c
@@ -371,8 +371,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);
@@ -690,8 +690,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