• Andreas Rheinhardt's avatar
    avformat/matroskaenc: Ensure that ChapterUID are != 0 · 3c3ad1de
    Andreas Rheinhardt authored
    AVChapters have an int as id field and therefore this value can appear
    <= 0. When remuxing from Matroska, this value actually contains
    the lower 32 bits of the original ChapterUID (which can be 64 bits).
    
    In order to ensure that the ChapterUID is always > 0, they were offset
    as follows (since 07704c61): First max(0, 1LL - chapter[i].id) was computed
    and stored in an uint32_t. And then the IDs were offset using this value.
    
    This has two downsides:
    1. It does not ensure that the UID is actually != 0: Namely if there is
    a chapter with id == INT_MIN, then the offset will be 2^31 + 1 and a
    chapter with id == INT_MAX will become 2^31 - 1 + 2^31 + 1 = 2^32 = 0,
    because the actual calculation was performed in 32 bits.
    2. As soon as a chapter id appears to be negative, a nontrivial offset
    is used, so that not even a ChapterUID that only uses 32 bits is
    preserved.
    
    So change this by treating the id as an unsigned value internally and
    only offset (by 1) if an id vanishes. The actual offsetting then has to
    be performed in 64 bits in order to make sure that no UINT32_MAX wraps
    around.
    Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
    3c3ad1de
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...