Commit b21727ae6f for ffmpeg
commit b21727ae6f097b9ca31cd0167e2d006dc9c09e63
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Sun Nov 1 10:54:42 2026 -0600
avcodec/opus/rc: avoid a 32-bit shift when flushing raw bits
ff_opus_rc_enc_end() pads the raw bits to a full word, which asks
ff_opus_rc_put_raw() for 32 bits when the cache is empty and shifts a
32-bit value by 32.
Use the value whole when all 32 bits fit, which writes the same output
without the undefined shift that aborts with --assert-level=2.
diff --git a/libavcodec/opus/rc.c b/libavcodec/opus/rc.c
index 57ac272934..f64078af3d 100644
--- a/libavcodec/opus/rc.c
+++ b/libavcodec/opus/rc.c
@@ -163,7 +163,7 @@ void ff_opus_rc_put_raw(OpusRangeCoder *rc, uint32_t val, uint32_t count)
const int to_write = FFMIN(32 - rc->rb.cachelen, count);
rc->total_bits += count;
- rc->rb.cacheval |= av_zero_extend(val, to_write) << rc->rb.cachelen;
+ rc->rb.cacheval |= (to_write < 32 ? av_zero_extend(val, to_write) : val) << rc->rb.cachelen;
rc->rb.cachelen = (rc->rb.cachelen + to_write) % 32;
if (!rc->rb.cachelen && count) {
@@ -171,7 +171,7 @@ void ff_opus_rc_put_raw(OpusRangeCoder *rc, uint32_t val, uint32_t count)
rc->rb.bytes += 4;
rc->rb.position -= 4;
rc->rb.cachelen = count - to_write;
- rc->rb.cacheval = av_zero_extend(val >> to_write, rc->rb.cachelen);
+ rc->rb.cacheval = to_write < 32 ? av_zero_extend(val >> to_write, rc->rb.cachelen) : 0;
av_assert0(rc->rng_cur < rc->rb.position);
}
}