[FFmpeg-devel] [PATCH] avutil/integer: ignore the upper bits of AVInteger in av_i2int()

James Almer jamrial at gmail.com
Fri Oct 21 16:00:47 EEST 2022


The function is meant to return the least significant 64 bits after all.
Should fix undefined behavior (left shift of negative values) as reported by ubsan.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavutil/integer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavutil/integer.c b/libavutil/integer.c
index b709c6d487..4ba33bcbc5 100644
--- a/libavutil/integer.c
+++ b/libavutil/integer.c
@@ -159,9 +159,9 @@ AVInteger av_int2i(int64_t a){
 
 int64_t av_i2int(AVInteger a){
     int i;
-    int64_t out=(int8_t)a.v[AV_INTEGER_SIZE-1];
+    int64_t out = a.v[AV_INTEGER_SIZE - 5];
 
-    for(i= AV_INTEGER_SIZE-2; i>=0; i--){
+    for (i = AV_INTEGER_SIZE - 6; i >= 0; i--) {
         out = (out<<16) + a.v[i];
     }
     return out;
-- 
2.37.3



More information about the ffmpeg-devel mailing list