FFmpeg git repo
Go to file
Andreas Rheinhardt 06fef1e9f1 avcodec/put_bits: Make skip_put_bits() less dangerous
Before c63c303a1f (the commit which
introduced a typedef for the type of the buffer of a PutBitContext)
skip_put_bits() was as follows:

static inline void skip_put_bits(PutBitContext *s, int n)
{
    s->bit_left -= n;
    s->buf_ptr  -= 4 * (s->bit_left >> 5);
    s->bit_left &= 31;
}

If s->bit_left was negative after the first subtraction, then the next
line will divide this by 32 with rounding towards -inf and multiply by
four; the result will be negative, of course.

The aforementioned commit changed this to:

static inline void skip_put_bits(PutBitContext *s, int n)
{
    s->bit_left -= n;
    s->buf_ptr  -= sizeof(BitBuf) * ((unsigned)s->bit_left / BUF_BITS);
    s->bit_left &= (BUF_BITS - 1);
}

Casting s->bit_left to unsigned meant that the rounding is still towards
-inf; yet the right side is now always positive (it transformed the
arithmetic shift into a logical shift), so that s->buf_ptr will always
be decremented (by about UINT_MAX / 8 unless n is huge) which leads to
segfaults on further usage and is already undefined pointer arithmetic
before that. This can be reproduced with the mpeg4 encoder with the
AV_CODEC_FLAG2_NO_OUTPUT flag set.

Furthermore, the earlier version as well as the new version share
another bug: s->bit_left will be in the range of 0..(BUF_BITS - 1)
afterwards, although the assumption throughout the other PutBitContext
functions is that it is in the range of 1..BUF_BITS. This might lead to
a shift by BUF_BITS in little-endian mode. This has been fixed, too.
The new version is furthermore able to skip zero bits, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-08 01:08:47 +02:00
compat compat/cuda/ptx2c: remove shell loop; fix BSD sed compat 2020-06-01 22:10:41 -05:00
doc avcodec: add adpcm_argo encoder 2020-08-07 23:04:28 +10:00
ffbuild ffbuild: Refine MIPS handling 2020-07-23 16:30:02 +02:00
fftools fftools/ffmpeg: make specifying thread_queue_size turn on threaded input 2020-07-29 23:10:12 +02:00
libavcodec avcodec/put_bits: Make skip_put_bits() less dangerous 2020-08-08 01:08:47 +02:00
libavdevice avdevice/decklink_dec: export timecode with s12m side data 2020-07-15 05:47:14 +08:00
libavfilter dnn_backend_native_layer_mathunary: add floor support 2020-08-07 10:34:22 +08:00
libavformat avformat: add argo_asf muxer 2020-08-07 23:14:28 +10:00
libavresample
libavutil avutil/channel_layout: add 22.2 layout 2020-08-04 00:17:56 +03:00
libpostproc Bump minor versions after branching 4.3 2020-06-08 22:49:04 +02:00
libswresample swresample/rematrix: treat 22.2 as 5.1 (back) when mixing 2020-08-04 00:17:56 +03:00
libswscale swscale/yuv2rgb: cosmetics 2020-07-25 10:20:42 +08:00
presets
tests fate: cosmetics 2020-08-07 23:14:29 +10:00
tools dnn_backend_native_layer_mathunary: add floor support 2020-08-07 10:34:22 +08:00
.gitattributes
.gitignore
.mailmap mailmap: add entry for myself 2020-07-13 11:24:04 +08:00
.travis.yml
Changelog avformat: add argo_asf muxer 2020-08-07 23:14:28 +10:00
configure libsvtav1: Rename without a _ 2020-07-31 22:30:35 +01:00
CONTRIBUTING.md
COPYING.GPLv2
COPYING.GPLv3
COPYING.LGPLv2.1
COPYING.LGPLv3
CREDITS
INSTALL.md
LICENSE.md
MAINTAINERS MAINTAINERS: add myself and gpg fingerprint 2020-07-17 21:57:18 +02:00
Makefile Makefile: Delete more created files when running "make distclean". 2020-03-11 11:43:01 +01:00
README.md
RELEASE RELEASE: We are after the 4.3 branch point, update for that 2020-06-10 00:20:24 +02:00

FFmpeg README

FFmpeg is a collection of libraries and tools to process multimedia content such as audio, video, subtitles and related metadata.

Libraries

  • libavcodec provides implementation of a wider range of codecs.
  • libavformat implements streaming protocols, container formats and basic I/O access.
  • libavutil includes hashers, decompressors and miscellaneous utility functions.
  • libavfilter provides a mean to alter decoded Audio and Video through chain of filters.
  • libavdevice provides an abstraction to access capture and playback devices.
  • libswresample implements audio mixing and resampling routines.
  • libswscale implements color conversion and scaling routines.

Tools

  • ffmpeg is a command line toolbox to manipulate, convert and stream multimedia content.
  • ffplay is a minimalistic multimedia player.
  • ffprobe is a simple analysis tool to inspect multimedia content.
  • Additional small tools such as aviocat, ismindex and qt-faststart.

Documentation

The offline documentation is available in the doc/ directory.

The online documentation is available in the main website and in the wiki.

Examples

Coding examples are available in the doc/examples directory.

License

FFmpeg codebase is mainly LGPL-licensed with optional components licensed under GPL. Please refer to the LICENSE file for detailed information.

Contributing

Patches should be submitted to the ffmpeg-devel mailing list using git format-patch or git send-email. Github pull requests should be avoided because they are not part of our review process and will be ignored.