[FFmpeg-devel] [PATCH 08/13] avcodec/wnv1: Use LE bitstream reader, avoid copying packet, fix memleak

Paul B Mahol onemda at gmail.com
Sat Aug 29 21:04:52 EEST 2020


On 8/29/20, Andreas Rheinhardt <andreas.rheinhardt at gmail.com> wrote:
> The Winnov WNV1 format is designed for a little-endian bitstream reader;
> yet our decoder reversed every byte bitwise (in a buffer only
> allocated for this purpose) to use a big-endian bitstream reader. This
> commit stops this.
>
> Two things needed to be done to achieve this: The codes in the table used
> to initialize a VLC reader needed to be reversed bitwise (when
> initializing a VLC in LE mode, it is expected that the first bit to be
> read is in the least significant bit; with BE codes the first bit to be
> read is the most significant bit of the code) and the following
> expression needed to be adapted:
>
> ff_reverse[get_bits(&w->gb, 8 - w->shift)]
>
> But this is easy: When only the bits read are reversed, they coincide
> with what a little-endian bitstream reader reads that reads the
> original, not-reversed data. But ff_reverse always reverses the full
> eight bits and this also performs a shift by (8 - (8 - w->shift)) on top
> of reversing the bits read. So the above line needs to be changed to
>
> get_bits(&w->gb, 8 - w->shift) << w->shift
>
> and this also shows why the variable shift is named the way it is.
>
> Finally, this also fixes a hypothetical memleak: For gigantic packets,
> initializing a GetBitContext can fail and in this case, the buffer
> containing the reversed data would leak.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
>  libavcodec/wnv1.c | 28 +++++++---------------------
>  1 file changed, 7 insertions(+), 21 deletions(-)
>

LGTM, nice.


More information about the ffmpeg-devel mailing list