1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-01-19 05:49:09 +02:00

101813 Commits

Author SHA1 Message Date
Michael Niedermayer
7f0353bc55 avcodec/faxcompr: Check remaining bits on error in decode_group3_1d_line()
Fixes: Timeout
Fixes: 32886/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-4779761466474496

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 7b3881f0da6da00cb6b5b123328e2fbfca936c47)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-18 20:53:56 +02:00
Michael Niedermayer
26369e6ca9 avformat/mov: check for pts overflow in mov_read_sidx()
Fixes: signed integer overflow: 9223372036846336888 + 4278255871 cannot be represented in type 'long'
Fixes: 32782/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-6059216516284416

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit ee53bb2399d8f387ac93a18ba0600ca7b04ac634)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-18 20:53:56 +02:00
Michael Niedermayer
246b3d58a9 avcodec/utils: Check ima wav duration for overflow
Fixes: signed integer overflow: 44331634 * 65 cannot be represented in type 'int'
Fixes: 32120/clusterfuzz-testcase-minimized-ffmpeg_dem_RSD_fuzzer-5760221223583744

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit f40e9b13554d88cbdd6cd2b4a3da2cbea9590f5d)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-18 20:53:56 +02:00
Michael Niedermayer
f4c5abe2d0 avcodec/rv10: Execute whole size check earlier for rv20
Fixes: Timeout
Fixes: 31380/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RV20_fuzzer-5230899257016320

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit f8556b632f4b29e54067ecba6f71ceb8af3806e4)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-18 20:53:56 +02:00
Michael Niedermayer
3d2af8afef avformat/cafdec: Check channels
Fixes: signed integer overflow: -1184429040541376544 * 32 cannot be represented in type 'long'
Fixes: 31788/clusterfuzz-testcase-minimized-ffmpeg_dem_CAF_fuzzer-6236746338664448

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 641c1db22bb27752b925293ad93f68843baa43bf)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-18 20:53:56 +02:00
Michael Niedermayer
48be6b27e7 avcodec/exr: increase vlc depth
Fixes: shift exponent -4 is negative
Fixes: 32265/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_EXR_fuzzer-465133454137753

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 3344079d3065c99563c65277be89ec694a7ca818)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-18 20:53:56 +02:00
Michael Niedermayer
b3f458f89f avcodec/dpx: Check bits_per_color earlier
Fixes: shift exponent 251 is too large for 32-bit type 'int'
Fixes: 32147/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DPX_fuzzer-5519111675314176

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit c093eb30311b7148a4da1c7555498187c8cdf0db)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-18 20:53:56 +02:00
Michael Niedermayer
b2a94f5937 avformat/mvi: Check audio_data_size to be non negative
Fixes: left shift of negative value -224
Fixes: 32144/clusterfuzz-testcase-minimized-ffmpeg_dem_MVI_fuzzer-4971479323246592

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 7e241a1b73bcca768f48ff1851e9e9f3f0752000)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-18 20:53:56 +02:00
Timo Rothenpieler
8d172d9409 avcodec/nvenc: disable s12m timestamps by default
Leads to weird crashes with valid looking input data for otherwise
unknown reasons.
2021-05-29 23:29:06 +02:00
Martin Storsjö
c813f5e343 aarch64: hevc_idct: Fix overflows in idct_dc
This is marginally slower, but correct for all input values.
The previous implementation failed with certain input seeds, e.g.
"checkasm --test=hevc_idct 98".

Signed-off-by: Martin Storsjö <martin@martin.st>
(cherry picked from commit f27e3ccf06ee19935d160164ca4a02f28cfc2a27)
2021-05-22 22:33:20 +03:00
Fei Wang
f7468a9c40 avcodec/vaapi_av1: pass full buffer size for each tile
Previously, only the size of a given tile was passed, making the
offset and size marked in VASliceParameterBufferAV1 invalid with
multiple tiles.

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
(cherry picked from commit 9b131e8500709fc7e66bf9049fc0a8f2c302cf9e)
2021-05-20 17:12:40 +03:00
Zane van Iperen
49e3dd7709
avcodec/videotoolboxenc: #define TARGET_CPU_ARM64 to 0 if not provided by the SDK
Fixes build failure on older SDKs without it.

Fixes #9242

(cherry picked from commit f9eb440e788c08c489bb1a6d24dbbe34f4597f1c)
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2021-05-19 10:40:30 +10:00
Anton Khirnov
e87e006121 lavc/pngdec: fix updating reference frames for APNG_DISPOSE_OP_BACKGROUND
They should be treated the same as APNG_DISPOSE_OP_NONE.

Broken in 5663301560.

Fixes #9184.

(cherry picked from commit aa726eaed9848bcf6f615d2d9e6e5dd6174ad570)
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2021-05-14 11:17:33 +02:00
Jan Ekström
70405dd7e3 ffmpeg: return no chosen output if an uninitialized stream is unavailable
Otherwise the rate emulation logic in `transcode_step` never gets
hit, and the unavailability flag never gets reset, leading to an
eternal loop with some rate emulation use cases.

This change was missed during the rework of ffmpeg.c, in which
encoder initialization was moved further down the time line in
commit 67be1ce0c6de330b1c10d1d121819d8a74a7b1f5 . Previously,
as the encoder initialization had happened earlier, this state was
not possible (flow getting as far as hitting the rate emulation logic,
yet not having the encoder initialized yet).

Fixes #9160

(cherry picked from commit ec20b8130269260f3ae1e4642da26ba556814f84)
2021-05-13 18:12:02 +03:00
Andreas Rheinhardt
74bcfe5f85 avcodec/h263, h263data: Move ff_h263_init_rl_inter to h263.c
The SVQ1 decoder does not need mpegvideo or rl.c, but it uses stuff
from h263data.c. But since 61fe481586425a41d45e371de1e875b49882477d
h263data.c called ff_rl_init() and this of course led to build errors
when the SVQ1 decoder is enabled and mpegvideo disabled.

Fix this by moving ff_h263_init_rl_inter() to h263.c.
Fixes ticket #9224.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit e2301feabc2be18e1ee878dcdf643fd78b90c735)
2021-05-12 07:03:32 +02:00
Andreas Rheinhardt
01701019e0 configure: Add missing mpegvideo dependency for IPU decoder
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit 8f588eea8e813304f14e1889cfdc79ab89a88deb)
2021-05-12 07:02:58 +02:00
Andreas Rheinhardt
70d1af5690 avcodec/ttmlenc: Don't confuse capabilities and caps_internal
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit 14a6025384ea7ebb97c6b718fbc91438abf94f37)
2021-05-10 22:20:22 +02:00
James Almer
75c3969292 avformat/mpegts: add missing sample_rate value to Opus extradata
Finishes fixing ticket #9190.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-02 20:54:59 -03:00
James Almer
40b896a781 avformat/movenc: fix writing dOps atoms
Don't blindly copy all bytes in extradata past ChannelMappingFamily. Instead
check if ChannelMappingFamily is not 0 and then only write the correct amount
of bytes from ChannelMappingTable, as defined in the spec[1].

Fixes part of ticket #9190.

[1] https://opus-codec.org/docs/opus_in_isobmff.html#4.3.2

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-02 20:54:59 -03:00
James Almer
ede71f4f57 avcodec/av1_metadata: don't store the inserted TD OBU in stack
Fixes: stack-use-after-return
Fixes: clusterfuzz-testcase-minimized-ffmpeg_BSF_AV1_METADATA_fuzzer-5931515701755904
Fixes: clusterfuzz-testcase-minimized-ffmpeg_BSF_AV1_METADATA_fuzzer-6105676541722624

Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-02 20:52:34 -03:00
Andreas Rheinhardt
023bc5d926 avcodec/nellymoserenc: Fix segfault when using unsupported channels/rate
NellyMoserEncodeContext.avctx is only set in init after these checks,
yet it is used by encode_end().
This is a regression since 0a56bfa71f751a2b25da8d060a019c1c75ca9d7b.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit 652279e35becae7b4c0b6b73e4f6c074e8a8b77c)
2021-04-29 02:28:20 +02:00
Brad Smith
7e9b9f24df avutil/cpu: Use HW_NCPUONLINE to detect # of online CPUs with OpenBSD
Signed-off-by: Brad Smith <brad@comstyle.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
(cherry picked from commit c8fb68ec52194d3de2f24a6850cd795d98eb2f2f)
2021-04-24 09:24:03 +02:00
Timo Rothenpieler
e3fb0f0c88 avcodec/nvenc: fix lossless tuning logic
Relying on the order of the enum is bad.
It clashes with the new presets having to sit at the end of the list, so
that they can be properly filtered out by the options parser on builds
with older SDKs.

So this refactors nvenc.c to instead rely on the internal NVENC_LOSSLESS
flag. For this, the preset mapping has to happen much earlier, so it's
moved from nvenc_setup_encoder to nvenc_setup_device and thus runs
before the device capability check.
2021-04-18 11:43:52 +02:00
Timo Rothenpieler
acb339bb88 avfilter/overlay_cuda: check av_buffer_ref result 2021-04-11 10:22:57 +02:00
Timo Rothenpieler
5873e06460 avfilter/overlay_cuda: hold explicit reference to hw_device_ctx 2021-04-11 10:22:54 +02:00
Andreas Rheinhardt
450f5ae49d avformat/matroskaenc: Fix leak when writing attachment without filename
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit 08c805f4ac767444ccc04a37ca6b99d719a6b58f)
2021-04-10 05:17:21 +02:00
Michael Niedermayer
f68ab9de4e Changelog: replace <next> by 4.4
Found-by: <jamrial>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-04-09 06:26:39 +02:00
Michael Niedermayer
dc91b913b6 RELEASE_NOTES: Based on the version from 4.3
Name suggested by Lynne, Gyan, Reto, Zane, Jan, Derek

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
n4.4
2021-04-08 22:55:16 +02:00
Michael Niedermayer
aeba1a4c20 avcodec/msp2dec: Check available space in RLE decoder
Fixes: out of array read
Fixes: 32968/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MSP2_fuzzer-5315296027082752

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit caaf4633117f77a545975dac18e85b8fcdbc9ce7)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-04-08 22:55:16 +02:00
Michael Niedermayer
d22550dd61 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>
(cherry picked from commit 0f6a3405e8987ad761a2d9139fdc95bbb6a61118)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-04-08 22:55:16 +02:00
Anton Khirnov
2a7f1bc282 lavc/pngdec: always create a copy for APNG_DISPOSE_OP_BACKGROUND
Calling av_frame_make_writable() from decoders is tricky, especially
when frame threading is used. It is much simpler and safer to just make
a private copy of the frame.
This is not expected to have a major performance impact, since
APNG_DISPOSE_OP_BACKGROUND is not used often and
av_frame_make_writable() would typically make a copy anyway.

Found-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit b593abda6c642cb0c3959752dd235c2faf66837f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-04-08 22:55:16 +02:00
Marton Balint
25e794a1ea avformat/url: add ff_make_absolulte_url2 to be able to test windows path cases
Signed-off-by: Marton Balint <cus@passwd.hu>
(cherry picked from commit fb4da90fecdefa2508618ca835cd0250be940e04)
2021-04-08 17:38:06 +02:00
Marton Balint
d622923b36 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>
(cherry picked from commit 5dc5f289cefe67457bd16f1950c56911e926385f)
2021-04-08 17:35:09 +02:00
Anton Khirnov
c64180fac8 lavc/pngdec: improve chunk length check
The length does not cover the chunk type or CRC.

(cherry picked from commit ae08eec6a1f2129cd231a0ab664f0f17b854d138)
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2021-04-08 14:15:30 +02:00
Anton Khirnov
8ee432dc23 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>
(cherry picked from commit 8d74baccff59192d395735036cd40a131a140391)
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2021-04-08 14:15:30 +02:00
Anton Khirnov
5f21bbed8a 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.

(cherry picked from commit 89ea5057bf47880145419341258eadb3635448cf)
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2021-04-08 14:15:30 +02:00
Anton Khirnov
53ecdbfbe5 lavc/pngdec: perform APNG blending in-place
Saves an allocation+free and two frame copies per each frame.

(cherry picked from commit 5a50bd88db670f8c030a814e4cdb2a880dc1d4f4)
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2021-04-08 14:15:30 +02:00
Andreas Rheinhardt
5c457c673f avcodec/mpegvideo_enc: Don't segfault on unorthodox mpeg_quant
The (deprecated) field AVCodecContext.mpeg_quant has no range
restriction; MpegEncContext.mpeg_quant is restricted to 0..1.
If the former is set, the latter is overwritten with it without
checking the range. This can trigger an av_assert2() with the MPEG-4
encoder when writing said field.

Fix this by just setting MpegEncContext.mpeg_quant to 1 if
AVCodecContext.mpeg_quant is set.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit d393c45051ddaf6146e7e29ec2ea97035a727529)
2021-04-08 11:59:08 +02:00
Andreas Rheinhardt
fb7cd45977 avcodec/encode: Fix check for allowed LJPEG pixel formats
The pix_fmts of the LJPEG encoder already contain all supported pixel
formats (including the ones only supported when strictness is unofficial
or less); yet the check in ff_encode_preinit() ignored this list in case
strictness is unofficial or less. But the encoder presumed that it is
always applied and blacklists some of the entries in pix_fmts when
strictness is > unofficial. The result is that if one uses an entry not
on that list and sets strictness to unofficial, said entry passes both
checks and this can lead to segfaults lateron (e.g. when using gray).

Fix this by removing the exception for LJPEG in ff_encode_preinit().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit 6e8e9b7633d8b755e7a464a10ba5047f31cbd84d)
2021-04-08 11:58:59 +02:00
Andreas Rheinhardt
44d218e99a avformat/rmdec: Don't rely on unspecified order of evaluation
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit 4666ce0aef395fc7dfa2a718e8d238e58e635d2a)
2021-04-08 11:58:05 +02:00
Andreas Rheinhardt
be5970fcaa avformat/rmdec: Fix memleaks upon read_header failure
For both the RealMedia as well as the IVR demuxer (which share the same
context) each AVStream's priv_data contains an AVPacket that might
contain data (even when reading the header) and therefore needs to be
unreferenced. Up until now, this has not always been done:

The RealMedia demuxer didn't do it when allocating a new stream's
priv_data failed although there might be other streams with packets to
unreference. (The reason for this was that until recently rm_read_close()
couldn't handle an AVStream without priv_data, so one had to choose
between a potential crash and a memleak.)

The IVR demuxer meanwhile never ever called read_close so that the data
already contained in packets leaks upon error.

This patch fixes both demuxers by adding the appropriate cleanup code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit 9a471c5437d34cd1e63520b47f50a0fa605a5688)
2021-04-08 11:57:57 +02:00
Andreas Rheinhardt
c72fca598c 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>
(cherry picked from commit 98060a198ef0bd213d0d0b029f8955fcd3be93d2)
2021-04-08 11:57:07 +02:00
Andreas Rheinhardt
b0997b8526 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>
(cherry picked from commit 9abda1365c5e2d827eb673b6d98245163c868bf1)
2021-04-08 11:56:44 +02:00
Andreas Rheinhardt
4562719c7d 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>
(cherry picked from commit 8ffd3ef9d94f33b411348c594a49d994b55c9550)
2021-04-08 11:56:35 +02:00
Andreas Rheinhardt
6d7dfabfb0 avcodec/mpegvideo: Factor common freeing code out
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit 9bab7de175d7c942a6ebddae6ba0cacdf360827e)
2021-04-08 11:56:26 +02:00
Andreas Rheinhardt
63277aa98e 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>
(cherry picked from commit ff0706cde8b1a1f483e26c0ccac117c23b23d604)
2021-04-08 11:56:17 +02:00
Andreas Rheinhardt
0155d5cd74 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>
(cherry picked from commit d4b9e117ceb6356cbcdc9ca81ec9c6c4b90efdae)
2021-04-08 11:56:07 +02:00
Andreas Rheinhardt
ed7efbe3ab avcodec/wmavoice: Check operations that can fail
There might be segfaults on failure.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit e93875b756b575438d7b825332739719d4fbc600)
2021-04-08 11:55:32 +02:00
Andreas Rheinhardt
6aad0b1bb5 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>
(cherry picked from commit a5b2f06b0c69221e375edd918a335c68b33d5667)
2021-04-08 11:55:17 +02:00
Andreas Rheinhardt
5621d10b7a avcodec/tiff: Avoid forward declarations
In this case it also fixes a potential for compilation failures:
Not all compilers can handle the case in which a function with
a forward declaration declared with an attribute to always inline it
is called before the function body appears. E.g. GCC 4.2.1 on OS X 10.6
doesn't like it.

Reviewed-by: Pavel Koshevoy <pkoshevoy@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
(cherry picked from commit e5d6af7b35d97f5c1252ecf8bd61f3295909fb6c)
2021-04-08 11:54:24 +02:00