From de4dc0bc67d648c8efd7fecab8d378d44317c5f0 Mon Sep 17 00:00:00 2001
From: Mr-Z-2697 <[email protected]&gt;
Date: Sun, 13 Jul 2025 16:09:53 +0800
Subject: [PATCH] Ensuring the mvdLX is compliant


The value of the mvdLX should be in the range of [-2^15, 2^15-1], as specified 
in H.265 7.4.9.9 Motion vector difference semantics.
However there was no safety check in this area, the mvdLX have been observed to 
exceed the range, under some rare circumstances.


This casting will cause overflow and underflow, should the mvd exceeds the 
int16_t range.
But because of the decoding process Equation 8-94 to 8-97, and the MV itself 
having the range of [-2^15, 2^15-1], the decoded MV will still be correct, and 
mvdLX will be in the legal range.
---
&nbsp;source/encoder/entropy.cpp | 5 +++--
&nbsp;1 file changed, 3 insertions(+), 2 deletions(-)


diff --git a/source/encoder/entropy.cpp b/source/encoder/entropy.cpp
index d4bf73d53..bc1c0d8e0 100644
--- a/source/encoder/entropy.cpp
+++ b/source/encoder/entropy.cpp
@@ -2104,8 +2104,9 @@ void Entropy::codeRefFrmIdx(const CUData&amp; cu, 
uint32_t absPartIdx, int list)
&nbsp;void Entropy::codeMvd(const CUData&amp; cu, uint32_t absPartIdx, int list)
&nbsp;{
&nbsp; &nbsp; &nbsp;const MV&amp; mvd = cu.m_mvd[list][absPartIdx];
- &nbsp; &nbsp;const int hor = mvd.x;
- &nbsp; &nbsp;const int ver = mvd.y;
+ &nbsp; &nbsp;// to ensure the mvdLX is in the range of [-2^15, 2^15-1]
+ &nbsp; &nbsp;const int16_t hor = (int16_t)mvd.x;
+ &nbsp; &nbsp;const int16_t ver = (int16_t)mvd.y;
&nbsp;
&nbsp; &nbsp; &nbsp;encodeBin(hor != 0 ? 1 : 0, m_contextState[OFF_MV_RES_CTX]);
&nbsp; &nbsp; &nbsp;encodeBin(ver != 0 ? 1 : 0, m_contextState[OFF_MV_RES_CTX]);
--&nbsp;
2.50.1.windows.1
_______________________________________________
x265-devel mailing list
[email protected]
https://mailman.videolan.org/listinfo/x265-devel

Reply via email to