[FFmpeg-cvslog] intfloat_readwrite: fix signed addition overflows

Mans Rullgard git at videolan.org
Mon Mar 19 05:30:41 CET 2012


ffmpeg | branch: release/0.8 | Mans Rullgard <mans at mansr.com> | Sat Oct  8 02:16:29 2011 +0100| [73ad066939bc435ba2cc47071a9dc617f8a9dda4] | committer: Reinhard Tartler

intfloat_readwrite: fix signed addition overflows

These additions might overflow the signed range for large
input values.  Converting to unsigned before the addition
rather than after avoids such undefined behaviour.  The
result under normal two's complement wraparound remains
unchanged.

Signed-off-by: Mans Rullgard <mans at mansr.com>
(cherry picked from commit 88d1e2b2b0a129365a62efd666db0394e8ffbe08)

Signed-off-by: Anton Khirnov <anton at khirnov.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=73ad066939bc435ba2cc47071a9dc617f8a9dda4
---

 libavutil/intfloat_readwrite.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavutil/intfloat_readwrite.c b/libavutil/intfloat_readwrite.c
index 21a1c31..4c8de7b 100644
--- a/libavutil/intfloat_readwrite.c
+++ b/libavutil/intfloat_readwrite.c
@@ -30,13 +30,13 @@
 #include "intfloat_readwrite.h"
 
 double av_int2dbl(int64_t v){
-    if(v+v > 0xFFEULL<<52)
+    if((uint64_t)v+v > 0xFFEULL<<52)
         return NAN;
     return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075);
 }
 
 float av_int2flt(int32_t v){
-    if(v+v > 0xFF000000U)
+    if((uint32_t)v+v > 0xFF000000U)
         return NAN;
     return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150);
 }



More information about the ffmpeg-cvslog mailing list