On 8/29/20, Andreas Rheinhardt <andreas.rheinha...@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.rheinha...@gmail.com> > --- > libavcodec/wnv1.c | 28 +++++++--------------------- > 1 file changed, 7 insertions(+), 21 deletions(-) >
LGTM, nice. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".