lavc/bitstream: avoid UB in bits_{read,peek}_signed(0)

bits_*_signed(0) will currently invoke an undefined shift by
8 * sizeof(int).

Add bits_*_signed_nz() that only works for n>0, analogous to
bits_read_nz(). Add an explicit check for n=0 in bits_*_signed().

Found-by: James Almer
This commit is contained in:
Anton Khirnov 2023-01-15 10:21:36 +01:00
parent bf23d530d2
commit 0b33310cd0
3 changed files with 39 additions and 3 deletions

View file

@ -85,7 +85,7 @@ typedef BitstreamContext GetBitContext;
#define get_bits1 bits_read_bit
#define get_bits64 bits_read_64
#define get_xbits bits_read_xbits
#define get_sbits bits_read_signed
#define get_sbits bits_read_signed_nz
#define get_sbits_long bits_read_signed
#define show_bits bits_peek
#define show_bits_long bits_peek