diff options
author | Nuo Mi <nuomi2021@gmail.com> | 2024-03-03 22:04:47 +0800 |
---|---|---|
committer | Nuo Mi <nuomi2021@gmail.com> | 2024-03-04 20:39:31 +0800 |
commit | 72b1237ece9acf509787a68357f4fb0857c893d9 (patch) | |
tree | dcdfb1d71be95b40aaeaef05edc9fb14da323cee | |
parent | 49ba613146b2e36001d6fcdda0c89b2142f2bb62 (diff) | |
download | ffmpeg-72b1237ece9acf509787a68357f4fb0857c893d9.tar.gz |
avcodec/vvcdec: fix undefined behaviours for derive_affine_mvc
libavcodec/vvc/vvc_inter.c:823:18: runtime error: signed integer overflow: 1426128896 + 1426128896 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior libavcodec/vvc/vvc_inter.c:823:18
Suggested-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r-- | libavcodec/vvc/vvc_inter.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c index d5be32aa14..c5629f7f6f 100644 --- a/libavcodec/vvc/vvc_inter.c +++ b/libavcodec/vvc/vvc_inter.c @@ -817,10 +817,13 @@ static void derive_affine_mvc(MvField *mvc, const VVCFrameContext *fc, const MvF const int vs = fc->ps.sps->vshift[1]; const MvField* mv2 = ff_vvc_get_mvf(fc, x0 + hs * sbw, y0 + vs * sbh); *mvc = *mv; - mvc->mv[0].x += mv2->mv[0].x; - mvc->mv[0].y += mv2->mv[0].y; - mvc->mv[1].x += mv2->mv[1].x; - mvc->mv[1].y += mv2->mv[1].y; + + // Due to different pred_flag, one of the motion vectors may have an invalid value. + // Cast them to an unsigned type to avoid undefined behavior. + mvc->mv[0].x += (unsigned int)mv2->mv[0].x; + mvc->mv[0].y += (unsigned int)mv2->mv[0].y; + mvc->mv[1].x += (unsigned int)mv2->mv[1].x; + mvc->mv[1].y += (unsigned int)mv2->mv[1].y; ff_vvc_round_mv(mvc->mv + 0, 0, 1); ff_vvc_round_mv(mvc->mv + 1, 0, 1); } |