diff --git a/lib/rbcodec/codecs/libffmpegFLAC/decoder.c b/lib/rbcodec/codecs/libffmpegFLAC/decoder.c index dc5a98cf5b..9701a598b2 100644 --- a/lib/rbcodec/codecs/libffmpegFLAC/decoder.c +++ b/lib/rbcodec/codecs/libffmpegFLAC/decoder.c @@ -165,7 +165,8 @@ static int decode_residuals(FLACContext *s, int32_t *decoded, int pred_order) for (; i < samples; i++) *decoded++ = tmp ? get_sbits(&gb, tmp) : 0; } else { - int real_limit = tmp ? (INT_MAX >> tmp) + 2 : INT_MAX; + unsigned lim = tmp ? (UINT_MAX >> tmp) + 2 : INT_MAX; + int real_limit = lim > INT_MAX ? INT_MAX : lim; for (; i < samples; i++) { int v = get_sr_golomb_flac(&gb, tmp, real_limit, 0); if ((unsigned) v == 0x80000000){ diff --git a/lib/rbcodec/codecs/libffmpegFLAC/golomb.h b/lib/rbcodec/codecs/libffmpegFLAC/golomb.h index 68d2558e1d..b62051ff1a 100644 --- a/lib/rbcodec/codecs/libffmpegFLAC/golomb.h +++ b/lib/rbcodec/codecs/libffmpegFLAC/golomb.h @@ -85,7 +85,7 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, buf = 0; } - buf += ((int32_t)i << k); + buf += ((unsigned int)i << k); } else if (i == limit - 1) { buf = SHOW_UBITS(re, gb, esc_len); LAST_SKIP_BITS(re, gb, esc_len); @@ -103,8 +103,9 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, * read signed golomb rice code (flac). */ static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ - int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); - return (v>>1) ^ -(v&1); + /* The folded value can use all 32 bits, so unfold it as unsigned. */ + unsigned int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); + return (int)((v>>1) ^ -(v&1)); } /**