Skip to content

Commit

Permalink
bitstream: Avoid undefined behavior in bitstream_skip()
Browse files Browse the repository at this point in the history
Do not use skip_remaining() to fully wipe the cache, as this could do
a 64-bit shift of a 64-bit variable which is undefined behavior in C.
Instead set the related variables to zero directly.

Thanks to Uoti for pointing out the problem.

CC: [email protected]
  • Loading branch information
lu-zero committed Jul 9, 2017
1 parent fd92daf commit 79f64f7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libavcodec/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,13 @@ static inline void skip_remaining(BitstreamContext *bc, unsigned n)
/* Skip n bits in the buffer. */
static inline void bitstream_skip(BitstreamContext *bc, unsigned n)
{
if (n <= bc->bits_left)
if (n < bc->bits_left)
skip_remaining(bc, n);
else {
n -= bc->bits_left;
skip_remaining(bc, bc->bits_left);
bc->bits = 0;
bc->bits_left = 0;

if (n >= 64) {
unsigned skip = n / 8;

Expand Down

0 comments on commit 79f64f7

Please sign in to comment.