diff mbox

[FFmpeg-devel] lavc/motion_est: Fix undefined negative left shifts

Message ID 201704181104.34300.cehoyos@ag.or.at
State Accepted
Commit b6a83962453463aa814bb79aeaa7145732158f02
Headers show

Commit Message

Carl Eugen Hoyos April 18, 2017, 9:04 a.m. UTC
Hi!

Attached patch fixes the following ubsan errors:
libavcodec/motion_est.c:959:42: runtime error: left shift of negative 
value -16
libavcodec/motion_est.c:960:42: runtime error: left shift of negative 
value -16

I do not have a testcase for lines 961f.

Please comment, Carl Eugen
From 4dd1b8d61c5dd2e77b7c855a1d2acf7d90277daf Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <cehoyos@ag.or.at>
Date: Tue, 18 Apr 2017 11:02:30 +0200
Subject: [PATCH] lavc/motion_est: Fix undefined negative left shifts.

---
 libavcodec/motion_est.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Michael Niedermayer April 18, 2017, 2:28 p.m. UTC | #1
On Tue, Apr 18, 2017 at 11:04:34AM +0200, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch fixes the following ubsan errors:
> libavcodec/motion_est.c:959:42: runtime error: left shift of negative 
> value -16
> libavcodec/motion_est.c:960:42: runtime error: left shift of negative 
> value -16
> 
> I do not have a testcase for lines 961f.
> 
> Please comment, Carl Eugen

>  motion_est.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 835e20f48e7c0b1df3bdba09f3723e21a4cfd155  0001-lavc-motion_est-Fix-undefined-negative-left-shifts.patch
> From 4dd1b8d61c5dd2e77b7c855a1d2acf7d90277daf Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
> Date: Tue, 18 Apr 2017 11:02:30 +0200
> Subject: [PATCH] lavc/motion_est: Fix undefined negative left shifts.

LGTM

thx

[...]
Carl Eugen Hoyos April 19, 2017, 9:40 p.m. UTC | #2
2017-04-18 16:28 GMT+02:00 Michael Niedermayer <michael@niedermayer.cc>:
> On Tue, Apr 18, 2017 at 11:04:34AM +0200, Carl Eugen Hoyos wrote:
>> Hi!
>>
>> Attached patch fixes the following ubsan errors:
>> libavcodec/motion_est.c:959:42: runtime error: left shift of negative
>> value -16
>> libavcodec/motion_est.c:960:42: runtime error: left shift of negative
>> value -16
>>
>> I do not have a testcase for lines 961f.
>>
>> Please comment, Carl Eugen
>
>>  motion_est.c |    8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>> 835e20f48e7c0b1df3bdba09f3723e21a4cfd155  0001-lavc-motion_est-Fix-undefined-negative-left-shifts.patch
>> From 4dd1b8d61c5dd2e77b7c855a1d2acf7d90277daf Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
>> Date: Tue, 18 Apr 2017 11:02:30 +0200
>> Subject: [PATCH] lavc/motion_est: Fix undefined negative left shifts.
>
> LGTM

Patch applied.

Thank you, Carl Eugen
diff mbox

Patch

diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index 25b606f..316d16a 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -956,10 +956,10 @@  void ff_estimate_p_frame_motion(MpegEncContext * s,
             P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1];
             if (P_TOP[1] > (c->ymax << shift))
                 P_TOP[1] =  c->ymax << shift;
-            if (P_TOPRIGHT[0] < (c->xmin << shift))
-                P_TOPRIGHT[0] =  c->xmin << shift;
-            if (P_TOPRIGHT[1] > (c->ymax << shift))
-                P_TOPRIGHT[1] =  c->ymax << shift;
+            if (P_TOPRIGHT[0] < (c->xmin * (1 << shift)))
+                P_TOPRIGHT[0] =  c->xmin * (1 << shift);
+            if (P_TOPRIGHT[1] > (c->ymax * (1 << shift)))
+                P_TOPRIGHT[1] =  c->ymax * (1 << shift);
 
             P_MEDIAN[0] = mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
             P_MEDIAN[1] = mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);