• Andreas Rheinhardt's avatar
    avcodec/flac_parser: Fix off-by-one error · e5e5be4c
    Andreas Rheinhardt authored
    The flac parser uses a fifo to buffer its data. Consequently, when
    searching for sync codes of flac packets, one needs to take care of
    the possibility of wraparound. This is done by using an optimized start
    code search that works on each of the continuous buffers separately and
    by explicitly checking whether the last pre-wrap byte and the first
    post-wrap byte constitute a valid sync code.
    
    Moreover, the last MAX_FRAME_HEADER_SIZE - 1 bytes ought not to be searched
    for (the start of) a sync code because a header that might be found in this
    region might not be completely available. These bytes ought to be searched
    lateron when more data is available or when flushing.
    
    Unfortunately there was an off-by-one error in the calculation of the
    length to search of the post-wrap buffer: It was too large, because the
    calculation was based on the amount of bytes available in the fifo from
    the last pre-wrap byte onwards. This meant that a header might be
    parsed twice (once prematurely and once regularly when more data is
    available); it could also mean that an invalid header will be treated as
    valid (namely if the length of said invalid header is
    MAX_FRAME_HEADER_SIZE and the invalid byte that will be treated as the
    last byte of this potential header happens to be the right CRC-8).
    
    Should a header be parsed twice, the second instance will be the best child
    of the first instance; the first instance's score will be
    FLAC_HEADER_BASE_SCORE - FLAC_HEADER_CHANGED_PENALTY ( = 3) higher than
    the second instance's score. So the frame belonging to the first
    instance will be output and it will be done as a zero length frame (the
    difference of the header's offset and the child's offset). This has
    serious consequences when flushing, as returning a zero length buffer
    signals to the caller that no more data will be output; consequently the
    last frames not yet output will be dropped.
    
    Furthermore, a "sample/frame number mismatch in adjacent frames" warning
    got output when returning the zero-length frame belonging to the first
    header, because the child's sample/frame number of course didn't match
    the expected sample frame/number given its parent.
    
    filter/hdcd-mix.flac from the FATE-suite was affected by this (the last
    frame was omitted) which is the reason why several FATE-tests needed to
    be updated.
    
    Fixes ticket #5937.
    Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
    e5e5be4c
Name
Last commit
Last update
..
aac.mak Loading commit data...
ac3.mak Loading commit data...
acodec.mak Loading commit data...
adpcm.mak Loading commit data...
alac.mak Loading commit data...
als.mak Loading commit data...
amrnb.mak Loading commit data...
amrwb.mak Loading commit data...
api.mak Loading commit data...
apng.mak Loading commit data...
atrac.mak Loading commit data...
audio.mak Loading commit data...
bmp.mak Loading commit data...
build.mak Loading commit data...
canopus.mak Loading commit data...
cbs.mak Loading commit data...
cdxl.mak Loading commit data...
checkasm.mak Loading commit data...
concatdec.mak Loading commit data...
cover-art.mak Loading commit data...
dca.mak Loading commit data...
demux.mak Loading commit data...
dfa.mak Loading commit data...
dnn.mak Loading commit data...
dnxhd.mak Loading commit data...
dpcm.mak Loading commit data...
ea.mak Loading commit data...
exif.mak Loading commit data...
ffmpeg.mak Loading commit data...
ffprobe.mak Loading commit data...
fft.mak Loading commit data...
fifo-muxer.mak Loading commit data...
filter-audio.mak Loading commit data...
filter-video.mak Loading commit data...
fits.mak Loading commit data...
flac.mak Loading commit data...
flvenc.mak Loading commit data...
gapless.mak Loading commit data...
gif.mak Loading commit data...
h264.mak Loading commit data...
hap.mak Loading commit data...
hevc.mak Loading commit data...
hlsenc.mak Loading commit data...
hw.mak Loading commit data...
id3v2.mak Loading commit data...
image.mak Loading commit data...
indeo.mak Loading commit data...
lavf-audio.mak Loading commit data...
lavf-container.mak Loading commit data...
lavf-image.mak Loading commit data...
lavf-image2pipe.mak Loading commit data...
lavf-video.mak Loading commit data...
libavcodec.mak Loading commit data...
libavdevice.mak Loading commit data...
libavformat.mak Loading commit data...
libavresample.mak Loading commit data...
libavutil.mak Loading commit data...
libswresample.mak Loading commit data...
libswscale.mak Loading commit data...
lossless-audio.mak Loading commit data...
lossless-video.mak Loading commit data...
matroska.mak Loading commit data...
microsoft.mak Loading commit data...
monkeysaudio.mak Loading commit data...
mov.mak Loading commit data...
mp3.mak Loading commit data...
mpc.mak Loading commit data...
mpeg4.mak Loading commit data...
mpegps.mak Loading commit data...
mpegts.mak Loading commit data...
mxf.mak Loading commit data...
opus.mak Loading commit data...
pcm.mak Loading commit data...
pixfmt.mak Loading commit data...
pixlet.mak Loading commit data...
probe.mak Loading commit data...
prores.mak Loading commit data...
qt.mak Loading commit data...
qtrle.mak Loading commit data...
real.mak Loading commit data...
screen.mak Loading commit data...
seek.mak Loading commit data...
segment.mak Loading commit data...
source-check.sh Loading commit data...
source.mak Loading commit data...
speedhq.mak Loading commit data...
subtitles.mak Loading commit data...
utvideo.mak Loading commit data...
vcodec.mak Loading commit data...
video.mak Loading commit data...
voice.mak Loading commit data...
vorbis.mak Loading commit data...
vpx.mak Loading commit data...
vqf.mak Loading commit data...
wavpack.mak Loading commit data...
wma.mak Loading commit data...
xvid.mak Loading commit data...