* [FFmpeg-devel] [PATCH] avcodec/vvcdec: check pred flag to fix undefined beavhiours
@ 2024-03-03 3:31 Nuo Mi
2024-03-03 6:45 ` Andreas Rheinhardt
2024-03-03 11:01 ` Frank Plowman
0 siblings, 2 replies; 4+ messages in thread
From: Nuo Mi @ 2024-03-03 3:31 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Nuo Mi
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
---
libavcodec/vvc/vvc_inter.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c
index d5be32aa14..48c566b097 100644
--- a/libavcodec/vvc/vvc_inter.c
+++ b/libavcodec/vvc/vvc_inter.c
@@ -816,13 +816,16 @@ static void derive_affine_mvc(MvField *mvc, const VVCFrameContext *fc, const MvF
const int hs = fc->ps.sps->hshift[1];
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;
- ff_vvc_round_mv(mvc->mv + 0, 0, 1);
- ff_vvc_round_mv(mvc->mv + 1, 0, 1);
+ for (int i = L0; i <= L1; i++) {
+ PredFlag mask = 1 << i;
+ if (mv2->pred_flag & mask) {
+ mvc->mv[i].x += mv2->mv[i].x;
+ mvc->mv[i].y += mv2->mv[i].y;
+ ff_vvc_round_mv(mvc->mv + i, 0, 1);
+ }
+ }
}
static void pred_affine_blk(VVCLocalContext *lc)
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/vvcdec: check pred flag to fix undefined beavhiours
2024-03-03 3:31 [FFmpeg-devel] [PATCH] avcodec/vvcdec: check pred flag to fix undefined beavhiours Nuo Mi
@ 2024-03-03 6:45 ` Andreas Rheinhardt
2024-03-03 14:06 ` Nuo Mi
2024-03-03 11:01 ` Frank Plowman
1 sibling, 1 reply; 4+ messages in thread
From: Andreas Rheinhardt @ 2024-03-03 6:45 UTC (permalink / raw)
To: ffmpeg-devel
Nuo Mi:
> 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
> ---
> libavcodec/vvc/vvc_inter.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c
> index d5be32aa14..48c566b097 100644
> --- a/libavcodec/vvc/vvc_inter.c
> +++ b/libavcodec/vvc/vvc_inter.c
> @@ -816,13 +816,16 @@ static void derive_affine_mvc(MvField *mvc, const VVCFrameContext *fc, const MvF
> const int hs = fc->ps.sps->hshift[1];
> 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;
> - ff_vvc_round_mv(mvc->mv + 0, 0, 1);
> - ff_vvc_round_mv(mvc->mv + 1, 0, 1);
> + for (int i = L0; i <= L1; i++) {
> + PredFlag mask = 1 << i;
> + if (mv2->pred_flag & mask) {
> + mvc->mv[i].x += mv2->mv[i].x;
> + mvc->mv[i].y += mv2->mv[i].y;
> + ff_vvc_round_mv(mvc->mv + i, 0, 1);
> + }
> + }
> }
>
> static void pred_affine_blk(VVCLocalContext *lc)
This adds branches; the UB alone could also be fixed/suppressed with
casting to unsigned. Would the latter cause any problems or are the
values set here unused lateron?
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/vvcdec: check pred flag to fix undefined beavhiours
2024-03-03 3:31 [FFmpeg-devel] [PATCH] avcodec/vvcdec: check pred flag to fix undefined beavhiours Nuo Mi
2024-03-03 6:45 ` Andreas Rheinhardt
@ 2024-03-03 11:01 ` Frank Plowman
1 sibling, 0 replies; 4+ messages in thread
From: Frank Plowman @ 2024-03-03 11:01 UTC (permalink / raw)
To: ffmpeg-devel
On 03/03/2024 03:31, Nuo Mi wrote:
> 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
> ---
> libavcodec/vvc/vvc_inter.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c
> index d5be32aa14..48c566b097 100644
> --- a/libavcodec/vvc/vvc_inter.c
> +++ b/libavcodec/vvc/vvc_inter.c
> @@ -816,13 +816,16 @@ static void derive_affine_mvc(MvField *mvc, const VVCFrameContext *fc, const MvF
> const int hs = fc->ps.sps->hshift[1];
> 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;
> - ff_vvc_round_mv(mvc->mv + 0, 0, 1);
> - ff_vvc_round_mv(mvc->mv + 1, 0, 1);
> + for (int i = L0; i <= L1; i++) {
> + PredFlag mask = 1 << i;
> + if (mv2->pred_flag & mask) {
> + mvc->mv[i].x += mv2->mv[i].x;
> + mvc->mv[i].y += mv2->mv[i].y;
> + ff_vvc_round_mv(mvc->mv + i, 0, 1);
> + }
> + }
> }
>
> static void pred_affine_blk(VVCLocalContext *lc)
LGTM. I happened to have a minimal case which reproduces this handy,
and the patch removes the error.
--
Frank
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/vvcdec: check pred flag to fix undefined beavhiours
2024-03-03 6:45 ` Andreas Rheinhardt
@ 2024-03-03 14:06 ` Nuo Mi
0 siblings, 0 replies; 4+ messages in thread
From: Nuo Mi @ 2024-03-03 14:06 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, Mar 3, 2024 at 2:43 PM Andreas Rheinhardt <
andreas.rheinhardt@outlook.com> wrote:
> Nuo Mi:
> > 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
> > ---
> > libavcodec/vvc/vvc_inter.c | 15 +++++++++------
> > 1 file changed, 9 insertions(+), 6 deletions(-)
> >
> > diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c
> > index d5be32aa14..48c566b097 100644
> > --- a/libavcodec/vvc/vvc_inter.c
> > +++ b/libavcodec/vvc/vvc_inter.c
> > @@ -816,13 +816,16 @@ static void derive_affine_mvc(MvField *mvc, const
> VVCFrameContext *fc, const MvF
> > const int hs = fc->ps.sps->hshift[1];
> > 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;
> > - ff_vvc_round_mv(mvc->mv + 0, 0, 1);
> > - ff_vvc_round_mv(mvc->mv + 1, 0, 1);
> > + for (int i = L0; i <= L1; i++) {
> > + PredFlag mask = 1 << i;
> > + if (mv2->pred_flag & mask) {
> > + mvc->mv[i].x += mv2->mv[i].x;
> > + mvc->mv[i].y += mv2->mv[i].y;
> > + ff_vvc_round_mv(mvc->mv + i, 0, 1);
> > + }
> > + }
> > }
> >
> > static void pred_affine_blk(VVCLocalContext *lc)
>
> This adds branches; the UB alone could also be fixed/suppressed with
> casting to unsigned. Would the latter cause any problems or are the
> values set here unused lateron?
>
It will not be used later.
sent a new patch based on your suggestion.
thank you
>
> - Andreas
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-03 14:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-03 3:31 [FFmpeg-devel] [PATCH] avcodec/vvcdec: check pred flag to fix undefined beavhiours Nuo Mi
2024-03-03 6:45 ` Andreas Rheinhardt
2024-03-03 14:06 ` Nuo Mi
2024-03-03 11:01 ` Frank Plowman
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git