diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-08-29 16:12:05 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2021-02-27 07:20:57 +0100 |
commit | c71de42131a524a3d9fa69209f899e84734cf1bc (patch) | |
tree | d6fa539dda7bb7c87ca0a4790b631c6882b55b69 /libavcodec/cbs_mpeg2_syntax_template.c | |
parent | d9da39572b42254f0f219daef34128eb39b80bf0 (diff) | |
download | ffmpeg-c71de42131a524a3d9fa69209f899e84734cf1bc.tar.gz |
avcodec/wnv1: Use LE bitstream reader, avoid copying packet, fix memleak
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.
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit 0166b1d1a6d052ef49aba3523d64f3c6d4f26372)
Diffstat (limited to 'libavcodec/cbs_mpeg2_syntax_template.c')
0 files changed, 0 insertions, 0 deletions