]> git.sesse.net Git - ffmpeg/commit
avcodec/ttaenc: Fix undefined shift
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 15 Sep 2019 20:01:20 +0000 (22:01 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 16 Sep 2019 19:30:19 +0000 (21:30 +0200)
commit3ab488a5407f833ecc66e8fa4c537dc4852db720
tree1617ddc39afc3cac0255e7dbcab71a7f1f25f123
parent551fcbbccbca8e78443c049421f01f350d4bc370
avcodec/ttaenc: Fix undefined shift

ttaenc contained (1 << unary) - 1 as an argument for a function
expecting an unsigned int. unary can be as big as 31 in this case.
The type of the shift and the whole expression is int, because 1 fits
into an integer, so that the behaviour is undefined if unary == 31
as the result of the shift can't be represented in an int §. Subtraction
by 1 (which makes the result of the whole expression representable in
an int) doesn't change that this is undefined (it usually leads to
signed integer overflow which is undefined, too).

The solution is simple: Make 1 unsigned to change the type of the
whole expression to unsigned int (as the function expects anyway).

Fixes ticket #8153.

§: This of course presupposes the common int range of -2^31..2^31-1

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/ttaenc.c