• Andreas Rheinhardt's avatar
    avformat/matroskaenc: Make ebml_num_size() more robust · 9b0f9003
    Andreas Rheinhardt authored
    Matroska (or actually EBML) uses variable-length numbers where only
    seven bits of every byte is usable for the length; the other bits encode
    the length of the variable-length number. So in order to find out how
    many bytes one needs to encode a given number one can use a loop like
    while (num >> 7 * bytes) bytes++; the Matroska muxer effectively did this.
    
    Yet it has a disadvantage: It is impossible for the result of a single
    right shift of an unsigned number with most significant bit set to be
    zero, because one can only shift by 0..(width - 1). On some
    architectures like x64 it is not even possible to do it with undefined
    right shifts in which case this leads to an infinite loop.
    
    This can be easily avoided by switching to a loop whose condition is
    (num >>= 7). The maximum value the so modified function can return
    is 10; any value > 8 is invalid and will now lead to an assert in
    put_ebml_num() or in start_ebml_master() (or actually in
    put_ebml_size_unknown()).
    Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
    9b0f9003
Name
Last commit
Last update
compat Loading commit data...
doc Loading commit data...
ffbuild Loading commit data...
fftools Loading commit data...
libavcodec Loading commit data...
libavdevice Loading commit data...
libavfilter Loading commit data...
libavformat Loading commit data...
libavresample Loading commit data...
libavutil Loading commit data...
libpostproc Loading commit data...
libswresample Loading commit data...
libswscale Loading commit data...
presets Loading commit data...
tests Loading commit data...
tools Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
CONTRIBUTING.md Loading commit data...
COPYING.GPLv2 Loading commit data...
COPYING.GPLv3 Loading commit data...
COPYING.LGPLv2.1 Loading commit data...
COPYING.LGPLv3 Loading commit data...
CREDITS Loading commit data...
Changelog Loading commit data...
INSTALL.md Loading commit data...
LICENSE.md Loading commit data...
MAINTAINERS Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
RELEASE Loading commit data...
configure Loading commit data...