[FFmpeg-cvslog] swresample/audioconvert: Fix undefined behavior ( left shift of negative value)

Michael Niedermayer git at videolan.org
Wed Oct 8 05:39:55 CEST 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Oct  8 04:18:27 2014 +0200| [344f8d307ac766c812b4c33331235e8ac9120a9f] | committer: Michael Niedermayer

swresample/audioconvert: Fix undefined behavior (left shift of negative value)

Fixes: asan_heap-oob_4da4f3_8_asan_heap-oob_4da4f3_419_scene1a.mm

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libswresample/audioconvert.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c
index efdc9b5..58b0bf3 100644
--- a/libswresample/audioconvert.c
+++ b/libswresample/audioconvert.c
@@ -52,8 +52,8 @@ static void CONV_FUNC_NAME(ofmt, ifmt)(uint8_t *po, const uint8_t *pi, int is, i
 
 //FIXME put things below under ifdefs so we do not waste space for cases no codec will need
 CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_U8 ,  *(const uint8_t*)pi)
-CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<8)
-CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<24)
+CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80U)<<8)
+CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80U)<<24)
 CONV_FUNC(AV_SAMPLE_FMT_FLT, float  , AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)*(1.0f/ (1<<7)))
 CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)*(1.0 / (1<<7)))
 CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_S16, (*(const int16_t*)pi>>8) + 0x80)



More information about the ffmpeg-cvslog mailing list