[FFmpeg-devel] [PATCH V1 1/2] avutil/common: Fix underflow for ROUNDED_DIV with unsigned integer

Jun Zhao mypopydev at gmail.com
Thu Oct 3 04:53:15 EEST 2019


From: Mengye Lv <mengyelv at tencent.com>

When used ROUNDED_DIV(a,b), if a is unsigned integer zero, it's
will lead to an underflow issue(it called unsigned integer
wrapping).

Fixes #8062

Signed-off-by: Mengye Lv <mengyelv at tencent.com>
Signed-off-by: Jun Zhao <barryjzhao at tencent.com>
---
 libavutil/common.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavutil/common.h b/libavutil/common.h
index af35397..f09f0b4 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -53,7 +53,7 @@
 //rounded division & shift
 #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
 /* assume b>0 */
-#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
+#define ROUNDED_DIV(a,b) (((a)>=0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
 /* Fast a/(1<<b) rounded toward +inf. Assume a>=0 and b>=0 */
 #define AV_CEIL_RSHIFT(a,b) (!av_builtin_constant_p(b) ? -((-(a)) >> (b)) \
                                                        : ((a) + (1<<(b)) - 1) >> (b))
-- 
1.7.1



More information about the ffmpeg-devel mailing list