From c72fa432349881d5a445cd110abf698cc94d490d Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 3 Dec 2016 23:44:56 +0100 Subject: [PATCH] avcodec/get_bits: Fix get_sbits_long(0) Fixes undefined behavior Fixes: 640889-media Found-by: Matt Wolenetz Signed-off-by: Michael Niedermayer --- libavcodec/get_bits.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index 0f183e0358..e8888419b5 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -369,6 +369,10 @@ static inline uint64_t get_bits64(GetBitContext *s, int n) */ static inline int get_sbits_long(GetBitContext *s, int n) { + // sign_extend(x, 0) is undefined + if (!n) + return 0; + return sign_extend(get_bits_long(s, n), n); }