]> git.sesse.net Git - ffmpeg/log
ffmpeg
3 years agofftools/ffmpeg: when framerate is set, prefer its inverse as output timebase
Anton Khirnov [Mon, 5 Apr 2021 08:44:36 +0000 (10:44 +0200)]
fftools/ffmpeg: when framerate is set, prefer its inverse as output timebase

Codec timebase is not well-defined for streamcopy, so it should only be
used as the last resort.

3 years agolavf/movenc: use framerate correctly in mov_write_tmcd_tag
Anton Khirnov [Sun, 4 Apr 2021 18:07:15 +0000 (20:07 +0200)]
lavf/movenc: use framerate correctly in mov_write_tmcd_tag

Current code uses its inverse.

3 years agolavc: postpone FF_API_AVCTX_TIMEBASE
Anton Khirnov [Sun, 4 Apr 2021 11:01:58 +0000 (13:01 +0200)]
lavc: postpone FF_API_AVCTX_TIMEBASE

There are still several decoders setting it and the situation is
non-trivial to resolve.

3 years agolavf: postpone removal of FF_API_COMPUTE_PKT_FIELDS2
Anton Khirnov [Sun, 4 Apr 2021 09:48:48 +0000 (11:48 +0200)]
lavf: postpone removal of FF_API_COMPUTE_PKT_FIELDS2

The infrastructure to fully handle generating timestamps e.g. for raw
video streamcopy is still not present.

3 years agolavf/webvttenc: fix avio_printf argument types after bump
Anton Khirnov [Sun, 4 Apr 2021 08:41:59 +0000 (10:41 +0200)]
lavf/webvttenc: fix avio_printf argument types after bump

Field precision supplied with the '*' specification must be an int.

3 years agolavf/matroskaenc: fix avio_printf argument types after bump
Anton Khirnov [Sun, 4 Apr 2021 08:41:59 +0000 (10:41 +0200)]
lavf/matroskaenc: fix avio_printf argument types after bump

Field precision supplied with the '*' specification must be an int.

Also, make sure converting those fields to int does not overflow.

3 years agolavc/pngdec: use a separate bytestream reader for each chunk
Anton Khirnov [Fri, 2 Apr 2021 14:33:44 +0000 (16:33 +0200)]
lavc/pngdec: use a separate bytestream reader for each chunk

This makes sure that reading a truncated chunk will never overflow into
the following chunk. It also allows to remove many repeated lines
skipping over the trailing crc checksum.

3 years agolavc/pngdec: improve chunk length check
Anton Khirnov [Fri, 2 Apr 2021 14:00:23 +0000 (16:00 +0200)]
lavc/pngdec: improve chunk length check

The length does not cover the chunk type or CRC.

3 years agotests/fate: add tests for PNG side/meta data
Anton Khirnov [Sun, 21 Mar 2021 10:10:34 +0000 (11:10 +0100)]
tests/fate: add tests for PNG side/meta data

3 years agolavc/pngdec: restructure exporting frame meta/side data
Anton Khirnov [Sat, 20 Mar 2021 18:57:25 +0000 (19:57 +0100)]
lavc/pngdec: restructure exporting frame meta/side data

This data cannot be stored in PNGDecContext.picture, because the
corresponding chunks may be read after the call to
ff_thread_finish_setup(), at which point modifying shared context data
is a race.

Store intermediate state in the context and then write it directly to
the output frame.

Fixes exporting frame metadata after 5663301560
Fixes #8972

Found-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agolavc/pngdec: remove unnecessary context variables
Anton Khirnov [Fri, 2 Apr 2021 08:45:27 +0000 (10:45 +0200)]
lavc/pngdec: remove unnecessary context variables

Do not store the image buffer pointer/linesize in the context, just
access them directly from the frame.
Stop assuming that linesize is the same for the current and last frame.

3 years agolavc/pngdec: perform APNG blending in-place
Anton Khirnov [Thu, 1 Apr 2021 13:45:45 +0000 (15:45 +0200)]
lavc/pngdec: perform APNG blending in-place

Saves an allocation+free and two frame copies per each frame.

3 years agoavcodec/vc1dec: Fix memleak upon allocation error
Andreas Rheinhardt [Wed, 7 Apr 2021 23:49:53 +0000 (01:49 +0200)]
avcodec/vc1dec: Fix memleak upon allocation error

ff_vc1_decode_init_alloc_tables() had one error path that forgot to free
already allocated buffers; these would then be overwritten on the next
allocation attempt (or they would just not be freed in case this
happened during init, as the decoders for which it is used do not have
the FF_CODEC_CAP_INIT_CLEANUP set).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agolavfi/dnn: add post process for detection
Guo, Yejun [Tue, 9 Mar 2021 06:51:42 +0000 (14:51 +0800)]
lavfi/dnn: add post process for detection

3 years agolavfi/dnn: refine code for frame pre/proc processing
Guo, Yejun [Mon, 1 Mar 2021 11:23:20 +0000 (19:23 +0800)]
lavfi/dnn: refine code for frame pre/proc processing

3 years agolavfi/dnn_backend_openvino.c: only allow DFT_PROCESS_FRAME to get output dim
Guo, Yejun [Mon, 15 Mar 2021 08:42:27 +0000 (16:42 +0800)]
lavfi/dnn_backend_openvino.c: only allow DFT_PROCESS_FRAME to get output dim

3 years agoavcodec/h261dec: Initialize IDCT context during init
Andreas Rheinhardt [Mon, 5 Apr 2021 00:42:18 +0000 (02:42 +0200)]
avcodec/h261dec: Initialize IDCT context during init

Before 998c9f15d1ca8c7489775ebcca51623b915988f1, initializing an
MpegEncContext's IDCT parts occured in ff_mpv_common_init() and this
has been called in h261_decode_frame(), not h261_decode_init().

Yet said commit factored this out of ff_mpv_common_init() and therefore
there is no reason any more not to set this during init as this commit
does.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/rv34, mpegvideo: Fix segfault upon frame size change error
Andreas Rheinhardt [Mon, 5 Apr 2021 00:05:58 +0000 (02:05 +0200)]
avcodec/rv34, mpegvideo: Fix segfault upon frame size change error

The RealVideo 3.0 and 4.0 decoders call ff_mpv_common_init() only during
their init function and not during decode_frame(); when the size of the
frame changes, they call ff_mpv_common_frame_size_change(). Yet upon
error, said function calls ff_mpv_common_end() which frees the whole
MpegEncContext and not only those parts that
ff_mpv_common_frame_size_change() reinits. As a result, the context will
never be usable again; worse, because decode_frame() contains no check
for whether the context is initialized or not, it is presumed that it is
initialized, leading to segfaults. Basically the same happens if
rv34_decoder_realloc() fails.

This commit fixes this by only resetting the parts that
ff_mpv_common_frame_size_change() changes upon error and by actually
checking whether the context is in need of reinitialization in
ff_rv34_decode_frame().

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/rv10: Don't presume context to be initialized
Andreas Rheinhardt [Sun, 4 Apr 2021 19:30:33 +0000 (21:30 +0200)]
avcodec/rv10: Don't presume context to be initialized

In case of resolution changes rv20_decode_picture_header() closes and
reopens its MpegEncContext; it checks the latter for errors, yet when
an error happens, it might happen that no new attempt at
reinitialization is performed when decoding the next frame; this leads
to crashes lateron.

This commit fixes this by making sure that initialization will always
be attempted if the context is currently not initialized.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/mpegvideo: Factor common freeing code out
Andreas Rheinhardt [Fri, 25 Dec 2020 13:57:38 +0000 (14:57 +0100)]
avcodec/mpegvideo: Factor common freeing code out

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegvideo: Fix memleak upon allocation error
Andreas Rheinhardt [Fri, 25 Dec 2020 13:17:10 +0000 (14:17 +0100)]
avcodec/mpegvideo: Fix memleak upon allocation error

When slice-threading is used, ff_mpv_common_init() duplicates
the first MpegEncContext and allocates some buffers for each
MpegEncContext (the first as well as the copies). But the count of
allocated MpegEncContexts is not updated until after everything has
been allocated and if an error happens after the first one has been
allocated, only the first one is freed; the others leak.

This commit fixes this: The count is now set before the copies are
allocated. Furthermore, the copies are now created and initialized
before the first MpegEncContext, so that the buffers exclusively owned
by each MpegEncContext are still NULL in the src MpegEncContext so
that no double-free happens upon allocation failure.

Given that this effectively touches every line of the init code,
it has also been factored out in a function of its own in order to
remove code duplication with the same code in
ff_mpv_common_frame_size_change() (which was never called when using
more than one slice (and if it were, there would be potential
double-frees)).

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoRevert "avcodec: add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ff_mpv_common...
Andreas Rheinhardt [Thu, 24 Dec 2020 13:36:22 +0000 (14:36 +0100)]
Revert "avcodec: add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ff_mpv_common_init()"

This mostly reverts commit 4b2863ff01b1fe93d9a518523c9098d17a9d8c6f.
Said commit removed the freeing code from ff_mpv_common_init(),
ff_mpv_common_frame_size_change() and ff_mpeg_framesize_alloc() and
instead added the FF_CODEC_CAP_INIT_CLEANUP to several codecs that use
ff_mpv_common_init(). This introduced several bugs:

a) Several decoders using ff_mpv_common_init() in their init function were
forgotten: This affected FLV, Intel H.263, RealVideo 3.0 and V4.0 as well as
VC-1/WMV3.
b) ff_mpv_common_init() is not only called from the init function of
codecs, it is also called from AVCodec.decode functions. If an error
happens after an allocation has succeeded, it can lead to memleaks;
furthermore, it is now possible for the MpegEncContext to be marked as
initialized even when ff_mpv_common_init() returns an error and this can
lead to segfaults because decoders that call ff_mpv_common_init() when
decoding a frame can mistakenly think that the MpegEncContext has been
properly initialized. This can e.g. happen with H.261 or MPEG-4.
c) Removing code for freeing from ff_mpeg_framesize_alloc() (which can't
be called from any init function) can lead to segfaults because the
check for whether it needs to allocate consists of checking whether the
first of the buffers allocated there has been allocated. This part has
already been fixed in 76cea1d2ce3f23e8131c8664086a1daf873ed694.
d) ff_mpv_common_frame_size_change() can also not be reached from any
AVCodec.init function; yet the changes can e.g. lead to segfaults with
decoders using ff_h263_decode_frame() upon allocation failure, because
the MpegEncContext will upon return be flagged as both initialized and
not in need of reinitialization (granted, the fact that
ff_h263_decode_frame() clears context_reinit before the context has been
reinited is a bug in itself). With the earlier version, the context
would be cleaned upon failure and it would be attempted to initialize
the context again in the next call to ff_h263_decode_frame().

While a) could be fixed by adding the missing FF_CODEC_CAP_INIT_CLEANUP,
keeping the current approach would entail adding cleanup code to several
other places because of b). Therefore ff_mpv_common_init() is again made
to clean up after itself; the changes to the wmv2 decoder and the SVQ1
encoder have not been reverted: The former fixed a memleak, the latter
allowed to remove cleanup code.

Fixes: double free
Fixes: ff_free_picture_tables.mp4
Fixes: ff_mpeg_update_thread_context.mp4
Fixes: decode_colskip.mp4
Fixes: memset.mp4
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavformat/url: add ff_make_absolulte_url2 to be able to test windows path cases
Marton Balint [Mon, 5 Apr 2021 23:10:30 +0000 (01:10 +0200)]
avformat/url: add ff_make_absolulte_url2 to be able to test windows path cases

Signed-off-by: Marton Balint <cus@passwd.hu>
3 years agoavformat/url: fix ff_make_absolute_url with Windows file paths
Marton Balint [Fri, 2 Apr 2021 15:07:54 +0000 (17:07 +0200)]
avformat/url: fix ff_make_absolute_url with Windows file paths

Ugly, but a lot less broken than it was.

Fixes ticket #9166.

Signed-off-by: Marton Balint <cus@passwd.hu>
3 years agoavformat/utils: add helper functions to retrieve index entries from an AVStream
James Almer [Tue, 23 Mar 2021 18:36:22 +0000 (15:36 -0300)]
avformat/utils: add helper functions to retrieve index entries from an AVStream

Signed-off-by: James Almer <jamrial@gmail.com>
3 years agodoc/muxers: fix alphabetical sorting of entries
Gyan Doshi [Wed, 7 Apr 2021 09:11:44 +0000 (14:41 +0530)]
doc/muxers: fix alphabetical sorting of entries

3 years agomov: Skip computing SAR from invalid display matrix elements
Vittorio Giovara [Tue, 30 Mar 2021 14:47:39 +0000 (16:47 +0200)]
mov: Skip computing SAR from invalid display matrix elements

3 years agoavcodec/bsf: Simplify getting codec name
Andreas Rheinhardt [Fri, 2 Apr 2021 13:21:51 +0000 (15:21 +0200)]
avcodec/bsf: Simplify getting codec name

All codec ids on BSF whitelists have a codec descriptor, so one can just
use avcodec_get_name() without worrying about the case of what happens
when no codec descriptor is found.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavformat/mov: check offset for overflow in mov_probe()
Michael Niedermayer [Sun, 4 Apr 2021 19:01:46 +0000 (21:01 +0200)]
avformat/mov: check offset for overflow in mov_probe()

Fixes: Invalid read of size 4
Fixes: ASAN_Deadlysignal.zip
Found-by: Hardik Shah <hardik05@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavcodec/options: Remove always-true check
Andreas Rheinhardt [Thu, 1 Apr 2021 21:16:37 +0000 (23:16 +0200)]
avcodec/options: Remove always-true check

Every codec has a name.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavutil/frame: Return 0 on success in av_frame_ref()
Andreas Rheinhardt [Thu, 1 Apr 2021 21:04:19 +0000 (23:04 +0200)]
avutil/frame: Return 0 on success in av_frame_ref()

av_frame_copy() is allowed to return values >= 0 on success, whereas
the documentation of av_frame_ref() states that the return value is 0 on
success. Ergo the latter must not just return the former's return value.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavformat/dss: Return 0 on success
Andreas Rheinhardt [Thu, 1 Apr 2021 21:02:18 +0000 (23:02 +0200)]
avformat/dss: Return 0 on success

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavformat/dss: Avoid using intermediate buffer
Andreas Rheinhardt [Thu, 1 Apr 2021 20:55:31 +0000 (22:55 +0200)]
avformat/dss: Avoid using intermediate buffer

All one needs is one byte beyond the end of the normal data; and because
the packet is padded, one already has it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavformat/dss: Set values known during read_header in read_header
Andreas Rheinhardt [Thu, 1 Apr 2021 20:31:13 +0000 (22:31 +0200)]
avformat/dss: Set values known during read_header in read_header

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavformat/mpegtsenc: Preserve disposition in the absence of language
Andreas Rheinhardt [Sat, 3 Apr 2021 05:14:40 +0000 (07:14 +0200)]
avformat/mpegtsenc: Preserve disposition in the absence of language

Implements ticket #9113.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavfilter/vf_find_rect: Use correct format specifier
Andreas Rheinhardt [Sun, 4 Apr 2021 09:26:47 +0000 (11:26 +0200)]
avfilter/vf_find_rect: Use correct format specifier

Fixes the following GCC warning:
warning: format ‘%lld’ expects argument of type ‘long long int’,
but argument 4 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]

Reviewed-by: Gyan Doshi <ffmpeg@gyani.pro>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoatomics: Fix the win32 atomic_exchange function
Martin Storsjö [Sat, 3 Apr 2021 21:04:46 +0000 (00:04 +0300)]
atomics: Fix the win32 atomic_exchange function

This fixes building with MSVC after
a2a38b160620d91bc3f895dadc4501c589998b9c.

Remove the stray semicolon, and add casts for the input argument
(which is an intptr_t*) to the right type (PVOID volatile *).

Signed-off-by: Martin Storsjö <martin@martin.st>
3 years agoavfilter/find_rect: write score to metadata
Gyan Doshi [Thu, 1 Apr 2021 13:16:20 +0000 (18:46 +0530)]
avfilter/find_rect: write score to metadata

3 years agoavfilter/find_rect: add option to discard non-matching frames
Gyan Doshi [Thu, 1 Apr 2021 12:52:03 +0000 (18:22 +0530)]
avfilter/find_rect: add option to discard non-matching frames

Default is disabled.

3 years agoavfilter/find_rect: improve logging
Gyan Doshi [Thu, 1 Apr 2021 12:39:25 +0000 (18:09 +0530)]
avfilter/find_rect: improve logging

Log now indicates timestamps of frames where a match is made.
Loglevel is changed to INFO since the user specifically wants this info.

3 years agoavcodec/wmavoice: Check operations that can fail
Andreas Rheinhardt [Sat, 3 Apr 2021 15:45:17 +0000 (17:45 +0200)]
avcodec/wmavoice: Check operations that can fail

There might be segfaults on failure.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/mjpegdec: Fix leak in case ICC array allocations fail partially
Andreas Rheinhardt [Sat, 3 Apr 2021 13:39:35 +0000 (15:39 +0200)]
avcodec/mjpegdec: Fix leak in case ICC array allocations fail partially

If only one of the two arrays used for the ICC profile could be
successfully allocated, it might be overwritten and leak when
the next ICC entry is encountered. Fix this by using a common struct,
so that one has only one array to allocate.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/cfhd: Keep track of which subbands have been read
Michael Niedermayer [Sat, 3 Apr 2021 14:04:48 +0000 (16:04 +0200)]
avcodec/cfhd: Keep track of which subbands have been read

This avoids use of uninitialized data
also several checks are inside the band reading code
so it is important that it is run at least once

Fixes: out of array accesses
Fixes: 28209/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5684714694377472
Fixes: 32124/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5425980681355264
Fixes: 30519/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-4558757155700736
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavcodec/cfhd: Require valid setup before Lowpass coefficients, BandHeader and BandSec...
Michael Niedermayer [Sat, 3 Apr 2021 13:19:22 +0000 (15:19 +0200)]
avcodec/cfhd: Require valid setup before Lowpass coefficients, BandHeader and BandSecondPass

Previously the code skipped all security checks when these where encountered but prior data was incorrect.
Also replace an always true condition by an assert

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavcodec/cfhd: Check transform_type consistently
Michael Niedermayer [Sat, 3 Apr 2021 12:40:50 +0000 (14:40 +0200)]
avcodec/cfhd: Check transform_type consistently

Fixes: out of array accesses
Fixes: 29754/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-6333598414274560
Fixes: 30519/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-6298424511168512
Fixes: 30739/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-5011292836462592
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavcodec/mjpegdec: Check initializing Huffman tables
Andreas Rheinhardt [Sat, 3 Apr 2021 14:00:56 +0000 (16:00 +0200)]
avcodec/mjpegdec: Check initializing Huffman tables

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/mjpegdec: Fix leak in case of invalid external Huffman tables
Andreas Rheinhardt [Sat, 3 Apr 2021 12:12:44 +0000 (14:12 +0200)]
avcodec/mjpegdec: Fix leak in case of invalid external Huffman tables

When using external Huffman tables fails during init, the decoder
reverts back to using the default Huffman tables; and when doing so,
the current VLC tables leak because init_default_huffman_tables()
doesn't free them before overwriting them.

Sample:
samples.ffmpeg.org/archive/all/avi+mjpeg+pcm_s16le++mjpeg-interlace.avi

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/a64multienc: Don't use static buffers, fix potential races
Andreas Rheinhardt [Sat, 3 Apr 2021 11:07:43 +0000 (13:07 +0200)]
avcodec/a64multienc: Don't use static buffers, fix potential races

render_charset() used static buffers that are always completely
initialized before every use, so that it is unnecessary for the
values in these arrays to be kept after leaving the function.
Given that this is not only unnecessary, but harmful due to the
possibility of data races if several instances of a64multi/a64multi5
run simultaneously these buffers have been replaced by ordinary buffers
on the stack (they are small enough for this).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/rawdec: Free bitstream_buf
Andreas Rheinhardt [Sat, 3 Apr 2021 09:54:12 +0000 (11:54 +0200)]
avcodec/rawdec: Free bitstream_buf

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agodoc/ffmpeg: clarify what -hwaccels list indicates
Gyan Doshi [Sat, 3 Apr 2021 05:25:12 +0000 (10:55 +0530)]
doc/ffmpeg: clarify what -hwaccels list indicates

Fixes #8204

3 years agoavformat/vividas: Fix crash when seeking without audio stream
Andreas Rheinhardt [Fri, 2 Apr 2021 19:03:39 +0000 (21:03 +0200)]
avformat/vividas: Fix crash when seeking without audio stream

The current code tries the access the codecpar of a nonexistent
audio stream when seeking. Stop that. Fixes ticket #9121.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavutil/cpu: Fix race condition in av_cpu_count()
Andreas Rheinhardt [Wed, 2 Dec 2020 22:57:16 +0000 (23:57 +0100)]
avutil/cpu: Fix race condition in av_cpu_count()

av_cpu_count() intends to emit a debug message containing the number of
logical cores when called the first time. The check currently works with
a static volatile int; yet this does not help at all in case of
concurrent accesses by multiple threads. So replace this with an
atomic_int.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/ass_split: Don't presume strlen to be >= 2
Andreas Rheinhardt [Tue, 1 Dec 2020 13:24:10 +0000 (14:24 +0100)]
avcodec/ass_split: Don't presume strlen to be >= 2

Fixes potential heap-buffer-overflow.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/binkaudio: Check return value of functions that can fail
Andreas Rheinhardt [Mon, 30 Nov 2020 21:30:49 +0000 (22:30 +0100)]
avcodec/binkaudio: Check return value of functions that can fail

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/binkaudio: Fix memleak upon init failure
Andreas Rheinhardt [Mon, 30 Nov 2020 21:24:10 +0000 (22:24 +0100)]
avcodec/binkaudio: Fix memleak upon init failure

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/flacenc: Fix memleak upon init error
Andreas Rheinhardt [Sun, 29 Nov 2020 21:28:37 +0000 (22:28 +0100)]
avcodec/flacenc: Fix memleak upon init error

An AVMD5 struct would leak if an error happened after its allocation.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/proresenc_anatoliy: Fix memleak upon init error
Andreas Rheinhardt [Fri, 27 Nov 2020 14:08:00 +0000 (15:08 +0100)]
avcodec/proresenc_anatoliy: Fix memleak upon init error

A buffer may leak in case of YUVA444P10 with dimensions that are not
both divisible by 16.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/bsf: Fix segfault when freeing half-allocated BSF
Andreas Rheinhardt [Fri, 2 Apr 2021 12:17:56 +0000 (14:17 +0200)]
avcodec/bsf: Fix segfault when freeing half-allocated BSF

When allocating a BSF fails, it could happen that the BSF's close
function has been called despite a failure to allocate the private data.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/av1_metadata_bsf: Check for the existence of units
Andreas Rheinhardt [Fri, 2 Apr 2021 15:16:39 +0000 (17:16 +0200)]
avcodec/av1_metadata_bsf: Check for the existence of units

Fixes a crash with ISOBMFF extradata containing no OBUs.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/h264_metadata_bsf: Don't add AUD to extradata
Andreas Rheinhardt [Fri, 2 Apr 2021 14:59:42 +0000 (16:59 +0200)]
avcodec/h264_metadata_bsf: Don't add AUD to extradata

This is a regression since switching to the generic CBS BSF code.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/tiff: Don't use separate temporary buffer for fax
Andreas Rheinhardt [Tue, 30 Mar 2021 06:26:43 +0000 (08:26 +0200)]
avcodec/tiff: Don't use separate temporary buffer for fax

Also don't unnecessarily copy the input data around if it needn't be
reversed; and remove a redundant memset -- av_fast_padded_malloc()
already does this for us.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/msmpeg4enc: Don't use code for static init that can fail
Andreas Rheinhardt [Thu, 10 Dec 2020 05:01:45 +0000 (06:01 +0100)]
avcodec/msmpeg4enc: Don't use code for static init that can fail

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavformat/dss: Don't prematurely modify context variable
Andreas Rheinhardt [Thu, 1 Apr 2021 20:07:40 +0000 (22:07 +0200)]
avformat/dss: Don't prematurely modify context variable

The DSS demuxer currently decrements a counter that should be positive
at the beginning of read_packet; should it become negative, it means
that the data to be read can't be read contiguosly, but has to be read
in two parts. In this case the counter is incremented again after the
first read if said read succeeded; if not, the counter stays negative.

This can lead to problems in further read_packet calls; in tickets #9020
and #9023 it led to segfaults if one tries to seek lateron if the seek
failed and generic seek tried to read from the beginning. But it could
also happen when av_new_packet() failed and the user attempted to read
again afterwards.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavformat/utils: Check allocations for failure
Andreas Rheinhardt [Thu, 1 Apr 2021 16:18:13 +0000 (18:18 +0200)]
avformat/utils: Check allocations for failure

There would be leaks in case of failure.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/ac3enc: Simplify AC-3 bit counting
Andreas Rheinhardt [Thu, 1 Apr 2021 14:47:11 +0000 (16:47 +0200)]
avcodec/ac3enc: Simplify AC-3 bit counting

When encoding E-AC-3, whether coupling is on or not determines whether
an additional frame based coupling exponent strategy element frmcplexpstr
(of size five bits) is present in the bitstream. So just add five to the
number of bits when counting them instead of adding 5*s->cpl_on (the
latter field is currently only 0 or 1, so it doesn't make a difference).

Furthermore, move some parts of the bit allocation that doesn't change
per-frame to count_frame_bits_fixed() (which is only run once during
init).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/[e]ac3enc: Fix indentation
Andreas Rheinhardt [Tue, 30 Mar 2021 18:01:17 +0000 (20:01 +0200)]
avcodec/[e]ac3enc: Fix indentation

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/ac3enc: Avoid needlessly copying encoded packets around
Andreas Rheinhardt [Mon, 29 Mar 2021 16:54:46 +0000 (18:54 +0200)]
avcodec/ac3enc: Avoid needlessly copying encoded packets around

AC-3 and EAC-3 are codecs whose packet sizes are known in advance,
so one can use the min_size parameter of ff_alloc_packet2() to
allocate exactly this amount. This avoids a memcpy later in
av_packet_make_refcounted() in encode_simple_internal().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/ac3enc: Use actual size of buffer in init_put_bits()
Andreas Rheinhardt [Mon, 29 Mar 2021 16:19:43 +0000 (18:19 +0200)]
avcodec/ac3enc: Use actual size of buffer in init_put_bits()

Since the very beginning (since de6d9b6404bfd1c589799142da5a95428f146edd)
the AC-3 encoder used AC3_MAX_CODED_FRAME_SIZE (namely 3840) for the
size of the output buffer (without any check at all).
This causes problems when encoding EAC-3 for which the maximum is too small,
smaller than the actual size of the buffer: One can run into asserts used
by the PutBits API. Ticket #8513 is about such a case and this commit
fixes it by using the real size of the buffer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agodoc/muxers: add entry for A64 muxer
Gyan Doshi [Fri, 2 Apr 2021 06:34:56 +0000 (12:04 +0530)]
doc/muxers: add entry for A64 muxer

3 years agodoc/encoders: add entry for a64 encoders
Gyan Doshi [Fri, 2 Apr 2021 09:43:39 +0000 (15:13 +0530)]
doc/encoders: add entry for a64 encoders

3 years agoavcodec/adpcmenc: don't share a single AVClass between multiple AVCodecs.
Zane van Iperen [Thu, 1 Apr 2021 10:31:35 +0000 (20:31 +1000)]
avcodec/adpcmenc: don't share a single AVClass between multiple AVCodecs.

Temporary fix until AVClass::child_class_next is gone.

Reviewed-By: James Almer <jamrial@gmail.com>
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
3 years agolibswscale/x86/yuv2yuvX: Removes unrolling for mmx and mmxext
Alan Kelly [Thu, 1 Apr 2021 10:00:15 +0000 (12:00 +0200)]
libswscale/x86/yuv2yuvX: Removes unrolling for mmx and mmxext

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agolibswscale/x86/swscale: Only call ff_yuv2yuvX functions if the input size is > 0
Alan Kelly [Thu, 1 Apr 2021 10:00:16 +0000 (12:00 +0200)]
libswscale/x86/swscale: Only call ff_yuv2yuvX functions if the input size is > 0

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agotests/checkasm/sw_scale: adds additional tests sizes for yux2yuvX
Alan Kelly [Thu, 1 Apr 2021 10:00:17 +0000 (12:00 +0200)]
tests/checkasm/sw_scale: adds additional tests sizes for yux2yuvX

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavformat/asf: Use ff_add_attached_pic() to read attached pics
Andreas Rheinhardt [Mon, 29 Mar 2021 07:01:50 +0000 (09:01 +0200)]
avformat/asf: Use ff_add_attached_pic() to read attached pics

Also removes a stack packet.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavformat/utils: Free new streams in ff_add_attached_pic on error
Andreas Rheinhardt [Mon, 29 Mar 2021 06:50:18 +0000 (08:50 +0200)]
avformat/utils: Free new streams in ff_add_attached_pic on error

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavformat: Add and use helper function to add attachment streams
Andreas Rheinhardt [Mon, 29 Mar 2021 05:58:56 +0000 (07:58 +0200)]
avformat: Add and use helper function to add attachment streams

All instances of adding attached pictures to a stream or adding
a stream and an attached packet to said stream have several things
in common like setting the index and flags of the packet, setting
the stream disposition etc. This commit therefore factors this out.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/flashsv2enc: Fix undefined NULL + 0
Andreas Rheinhardt [Fri, 26 Mar 2021 17:35:25 +0000 (18:35 +0100)]
avcodec/flashsv2enc: Fix undefined NULL + 0

Affected the vsynth*-flashsv2 FATE-tests.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavutil/pixdesc: Fix 1 << 32
Andreas Rheinhardt [Fri, 26 Mar 2021 17:22:24 +0000 (18:22 +0100)]
avutil/pixdesc: Fix 1 << 32

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/motion_est: Fix invalid left shift of negative numbers
Andreas Rheinhardt [Fri, 26 Mar 2021 17:18:05 +0000 (18:18 +0100)]
avcodec/motion_est: Fix invalid left shift of negative numbers

Affected many FATE-tests.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavfilter/vf_codecview: Fix undefined left shifts of negative numbers
Andreas Rheinhardt [Fri, 26 Mar 2021 15:24:59 +0000 (16:24 +0100)]
avfilter/vf_codecview: Fix undefined left shifts of negative numbers

Affected the filter-codecview-mvs FATE-test.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/g2meet: Fix undefined NULL + 0
Andreas Rheinhardt [Fri, 26 Mar 2021 15:17:04 +0000 (16:17 +0100)]
avcodec/g2meet: Fix undefined NULL + 0

Affected the g2m4 FATE-test.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavutil/base64: Fix undefined NULL + 0
Andreas Rheinhardt [Fri, 26 Mar 2021 15:03:27 +0000 (16:03 +0100)]
avutil/base64: Fix undefined NULL + 0

Affected the base64 FATE test.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/vmdvideo: Fix NULL + 0
Andreas Rheinhardt [Fri, 26 Mar 2021 14:12:10 +0000 (15:12 +0100)]
avcodec/vmdvideo: Fix NULL + 0

Affected the FATE tests filter-gradfun-sample and sierra-vmd-video.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mss12: Don't apply non-zero offset to null pointer
Andreas Rheinhardt [Fri, 26 Mar 2021 13:40:40 +0000 (14:40 +0100)]
avcodec/mss12: Don't apply non-zero offset to null pointer

Affected the FATE tests mss2-wmv and mss1-pal.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/lcldec: Fix undefined NULL + 0
Andreas Rheinhardt [Fri, 26 Mar 2021 13:11:18 +0000 (14:11 +0100)]
avcodec/lcldec: Fix undefined NULL + 0

Affected the FATE tests vsynth*-zlib, mszh and zlib.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/qtrleenc: Fix negative linesizes, don't use NULL + offset
Andreas Rheinhardt [Fri, 26 Mar 2021 12:37:43 +0000 (13:37 +0100)]
avcodec/qtrleenc: Fix negative linesizes, don't use NULL + offset

Before commit f1e17eb446577180ee9976730aacb46563766518, the qtrle
encoder had undefined pointer arithmetic: Outside of a loop, two
pointers were set to point to the ith element (with index i-1) of
a line of a frame. At the end of each loop iteration, these pointers
were decremented, so that they pointed to the -1th element of the line
after the loop. Furthermore, one of these pointers can be NULL (in which
case all pointer arithmetic is automatically undefined behaviour).

Commit f1e17eb44 added a check in order to ensure that the elements
never point to the -1th element of the array: The pointers are only
decremented if they are bigger than the frame's base pointer
(i.e. AVFrame.data[0]). Yet this check does not work at all in case of
negative linesizes; furthermore in case the pointer that can be NULL is
NULL initializing it still involves undefined pointer arithmetic.

This commit fixes both of these issues: First, non-NULL pointers are
initialized to point to the element after the ith element and
decrementing is moved to the beginning of the loop. Second, if a pointer
is NULL, it is just made to point to the other pointer, as this allows
to avoid checks before decrementing it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/qtrleenc: Use keyframe when no previous frame is available
Andreas Rheinhardt [Fri, 26 Mar 2021 11:42:21 +0000 (12:42 +0100)]
avcodec/qtrleenc: Use keyframe when no previous frame is available

If keeping a reference to an earlier frame failed, the next frame must
be an I frame for lack of reference frame. This commit implements this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agolibswresample/audioconvert: Fix undefined NULL + 0
Andreas Rheinhardt [Fri, 26 Mar 2021 08:43:22 +0000 (09:43 +0100)]
libswresample/audioconvert: Fix undefined NULL + 0

Affected 26 FATE tests like swr-resample_async-s16p-44100-8000.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/proresdec2: Don't apply non-zero offset to null pointer
Andreas Rheinhardt [Fri, 26 Mar 2021 08:21:22 +0000 (09:21 +0100)]
avcodec/proresdec2: Don't apply non-zero offset to null pointer

Affected ProRes without alpha; affected 32 FATE tests, e.g. prores-422,
prores-422_proxy, prores-422_lt or matroska-prores-header-insertion-bz2.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegvideo_enc: Don't apply non-zero offset to null pointer
Andreas Rheinhardt [Fri, 26 Mar 2021 06:15:56 +0000 (07:15 +0100)]
avcodec/mpegvideo_enc: Don't apply non-zero offset to null pointer

Affected many FATE tests (mostly vsynth ones).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavfilter/af_hdcd: Fix undefined shifts
Andreas Rheinhardt [Fri, 26 Mar 2021 05:22:24 +0000 (06:22 +0100)]
avfilter/af_hdcd: Fix undefined shifts

Affected the filter-hdcd-* FATE tests.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/dcaenc: Fix undefined left shift of negative numbers
Andreas Rheinhardt [Fri, 26 Mar 2021 05:03:49 +0000 (06:03 +0100)]
avcodec/dcaenc: Fix undefined left shift of negative numbers

Affected the acodec-dca and acodec-dca2 FATE tests.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agotests/matroska: Add test for remuxing annex B H.264 into Matroska
Andreas Rheinhardt [Wed, 31 Mar 2021 18:25:04 +0000 (20:25 +0200)]
tests/matroska: Add test for remuxing annex B H.264 into Matroska

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
3 years agoavcodec/pnm_parser: Check image size addition for overflow
Michael Niedermayer [Tue, 30 Mar 2021 11:22:14 +0000 (13:22 +0200)]
avcodec/pnm_parser: Check image size addition for overflow

Fixes: assertion failure
Fixes: out of array access
Fixes: 32664/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PGMYUV_fuzzer-6533642202513408.fuzz
Fixes: 32669/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PGMYUV_fuzzer-6001928875147264
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavcodec/lscrdec: Check length in decode_idat()
Michael Niedermayer [Tue, 30 Mar 2021 11:17:09 +0000 (13:17 +0200)]
avcodec/lscrdec: Check length in decode_idat()

Fixes: out of array access
Fixes: 32264/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LSCR_fuzzer-6684504010915840
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agotools/target_dem_fuzzer: Fix packet leak
Michael Niedermayer [Mon, 22 Mar 2021 20:58:30 +0000 (21:58 +0100)]
tools/target_dem_fuzzer: Fix packet leak

Fixes: 32121/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-4512973109460992
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavformat/imx: Check palette chunk size
Michael Niedermayer [Tue, 30 Mar 2021 10:47:22 +0000 (12:47 +0200)]
avformat/imx: Check palette chunk size

Fixes: out of array write
Fixes: 32116/clusterfuzz-testcase-minimized-ffmpeg_dem_SIMBIOSIS_IMX_fuzzer-6702533894602752
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavcodec/h265_metadata_bsf: Check nb_units before accessing the first in h265_metadata...
Michael Niedermayer [Tue, 30 Mar 2021 10:36:08 +0000 (12:36 +0200)]
avcodec/h265_metadata_bsf: Check nb_units before accessing the first in h265_metadata_update_fragment()

Fixes: null pointer dereference
Fixes: 32113/clusterfuzz-testcase-minimized-ffmpeg_BSF_HEVC_METADATA_fuzzer-4803262287052800
Same as 0c48c332eeb2866d9353125f701e099c48889463

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavformat/rmdec: use larger intermediate type for audio_framesize * sub_packet_h check
Michael Niedermayer [Tue, 30 Mar 2021 09:03:56 +0000 (11:03 +0200)]
avformat/rmdec: use larger intermediate type for audio_framesize * sub_packet_h check

Fixes: signed integer overflow: 65535 * 65535 cannot be represented in type 'int'
Fixes: 31406/clusterfuzz-testcase-minimized-ffmpeg_dem_IVR_fuzzer-5024692843970560
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>