1
mirror of https://git.videolan.org/git/ffmpeg.git synced 2024-09-05 15:58:07 +02:00
Commit Graph

454 Commits

Author SHA1 Message Date
Andreas Rheinhardt
1ea3650823 Replace all occurences of av_mallocz_array() by av_calloc()
They do the same.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-20 01:03:52 +02:00
Andreas Rheinhardt
6bf95c2066 avcodec/vp3: Mark decoders as init-threadsafe
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-05-10 23:13:30 +02:00
Andreas Rheinhardt
802166f709 avcodec/vp3: Reindentation
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-05-10 23:13:14 +02:00
Andreas Rheinhardt
80b5c4bc08 avcodec/vp3: Avoid code duplication when initializing coeff_vlcs
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-05-10 23:12:15 +02:00
Andreas Rheinhardt
9afb291267 avcodec/vp3: Don't try to decode VP4 when VP4 decoder is disabled
Otherwise decoding will crash lateron; e.g. because dct_tokens
is never set or because a VLC that has not been allocated is used.

Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-05-10 23:11:35 +02:00
Andreas Rheinhardt
a247ac640d avcodec: Constify AVCodecs
Given that the AVCodec.next pointer has now been removed, most of the
AVCodecs are not modified at all any more and can therefore be made
const (as this patch does); the only exceptions are the very few codecs
for external libraries that have a init_static_data callback.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:15 -03:00
Michael Niedermayer
869fe41d10 avcodec/vp3: Check input amount in theora_decode_header()
Fixes: Timeout
Fixes: 29226/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_THEORA_fuzzer-6195092572471296

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-01-31 14:37:07 +01:00
Anton Khirnov
e15371061d lavu/mem: move the DECLARE_ALIGNED macro family to mem_internal on next+1 bump
They are not properly namespaced and not intended for public use.
2021-01-01 14:14:57 +01:00
Andreas Rheinhardt
420476ec78 avcodec/vp3: Remove code duplication when initializing Theora VLCs
theora_init_huffman_tables() does essentially the same as
ff_init_vlcs_from_lengths().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:47 +01:00
Andreas Rheinhardt
802fc678b2 avcodec/vp3: Use symbols table for VP3 motion vectors
Expressions like array[get_vlc2()] can be optimized by using a symbols
table if the array is always the same for a given VLC. This requirement
is fulfilled for the VLC used for VP3 motion vectors. The reason it
hasn't been done before is probably that the array in this case
contained entries in the range -31..31; but this is no problem with
ff_init_vlc_from_lengths(): Just apply an offset of 31 to the symbols
before storing them in the table used to initialize VP3 motion vectors
and apply an offset of -31 when initializing the actual VLC.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:47 +01:00
Andreas Rheinhardt
4cb4345f78 avcodec/vp3: Make tables used to initialize VLCs smaller
This is possible by switching to ff_init_vlc_from_lengths() because it
allows to replace codes of type uint16_t by symbols of type uint8_t; in
some cases (like here) it also allows to replace explicitly coded
codes by implicitly coded symbols.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:46 +01:00
Andreas Rheinhardt
22241d12c7 avcodec/vp3: Apply VLC offset during init
By switching to ff_init_vlc_from_lengths() one can apply both positive
as well as negative offsets for free; in this case it even saves space
because one replaces codes tables that don't fit into an uint8_t by
symbols tables that fit into an uint8_t or can even be completely
avoided as they are trivial.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:46 +01:00
Andreas Rheinhardt
9b45c6d74b avcodec/vp3: Don't check for errors for complete VLC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-29 11:22:35 +01:00
Andreas Rheinhardt
c69392a54c avcodec/vp3: Make parsing Theora Huffman tables more spec-compliant
Theora allows to use custom Huffman tables which are coded in the
bitstream as a tree: Whether the next node is a leaf or not is coded
in a bit; each node itself contains a five bit token. Each tree can
contain at most 32 leafs; typically they contain exactly 32 with the 32
symbols forming a permutation of 0..31. Yet the standard does not impose
either of these requirements. It explicitly allows less than 32 leafs
and multiple codes with the same token.

But our decoder used an algorithm that required the codes->token mapping
to be injective and that also presumed that there be at least two leafs:
Instead of using an array for codes, tokens and code lengths, the
decoder only had arrays for codes and code lengths. The code and length
for a given token were stored in entry[token]. As no symbols table was
used when initializing the VLC, the default one applied and therefore
the entry[token] got the symbol token (if the length of said entry is >0).
Yet if multiple codes had the same token, the codes and lengths from the
later token would overwrite the earlier codes and lengths.

Furthermore, less than 32 leafs could also lead to problems: Namely if
this was not the first time Huffman tables have been parsed in which
case the array is not zeroed initially so that old entries could make
the new table invalid.

libtheora seems to always use 32 leafs and no duplicate tokens; I am not
aware of any existing valid files that do not.

This is fixed by using a codes, symbols and lengths array when
initializing the VLC. In order to reduce the amount of stuff kept in the
context only the symbols and lengths (which both fit into an uint8_t)
are kept in the context; the codes are derived from the lengths
immediately before creating the tables.

There is now only one thing left which is not spec-compliant: Trees with
only one node (which has length zero) are not supported by
ff_init_vlc_sparse() yet.

Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-26 07:15:37 +01:00
Andreas Rheinhardt
289e964873 avcodec/vp3: Unify initializing and freeing VLC tables
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-21 06:53:41 +02:00
Andreas Rheinhardt
786b1b0c44 avcodec/vp3: Check allocations of VLCs
It would lead to crashs lateron if they failed.

Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-21 06:16:16 +02:00
Andreas Rheinhardt
a01ca21bbb avcodec/vp3: Fix memleak upon init failure
Up until now, there was no cleanup in case initializing the Theora VLC
tables failed, leading to memleaks. This commit gets rid of them by
setting the FF_CODEC_CAP_INIT_CLEANUP flag for all decoders in vp3.c;
this also allows to remove some (now redundant) cleanup code.

Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-21 05:46:04 +02:00
Peter Ross
3e5f0cf271 avcodec/vp3: fix indentation 2020-04-17 19:33:43 +10:00
Anton Khirnov
1f4cf92cfb pthread_frame: merge the functionality for normal decoder init and init_thread_copy
The current design, where
- proper init is called for the first per-thread context
- first thread's private data is copied into private data for all the
  other threads
- a "fixup" function is called for all the other threads to e.g.
  allocate dynamically allocated data
is very fragile and hard to follow, so it is abandoned. Instead, the
same init function is used to init each per-thread context. Where
necessary, AVCodecInternal.is_copy can be used to differentiate between
the first thread and the other ones (e.g. for decoding the extradata
just once).
2020-04-10 15:24:54 +02:00
Anton Khirnov
665e5b0fba lavc: replace AVCodecInternal.allocate_progress with an internal cap
This is a constant codec property, so a capability flag is more appropriate.
2020-04-10 14:16:39 +02:00
Peter Ross
31c4fe177d avcodec/vp3: propagate error codes
throughout vp3_decode_frame the error code was being captured (ret) but never returned.

Signed-off-by: Peter Ross <pross@xvid.org>
Reviewed-by: Anton Khirnov <anton@khirnov.net>
2020-04-07 20:59:15 +10:00
Anton Khirnov
1b17988cb5 vp3: eliminate copy_fields
It is very fragile against fields being moved and hides what is actually
being copied. Copy all the fields explicitly instead.
2020-03-16 09:27:17 +01:00
Michael Niedermayer
a15d904ad7 avcodec: Replace get_bits_long() by get_bits() where possible
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-12-31 18:43:50 +01:00
Peter Ross
fd17218558 vp4: prevent unaligned memory access in loop filter
VP4 applies a loop filter during motion compensation, causing the block offset
will often by unaligned. This produces a bus error on some platforms, namely
ARMv7 NEON.

This patch adds a unaligned version of the loop filter function pointer
to VP3DSPContext.

Reported-by: Mike Melanson <mike@multimedia.cx>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-10-30 10:06:38 +01:00
Michael Niedermayer
daf92cc074 avcodec/vp3: Check for end of input in 2 places of vp4_unpack_macroblocks()
Fixes: Timeout (82sec -> 1sec)
Fixes: 16411/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-5166958151991296

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-02 18:09:11 +02:00
Michael Niedermayer
58c7f419ce avcodec/vp3: Check for end of input in vp4_unpack_vlcs()
Fixes: Timeout (too long -> 1sec)
Fixes: 15232/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-5769583086010368

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-08-03 12:05:37 +02:00
Michael Niedermayer
b4bf7226af avcodec/vp3: Check that theora is theora
Theora is forced to be non zero if it is zero and a sample
is asked for, as suggested by reimar

Fixes: Timeout (2min -> 600ms)
Fixes: 15366/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_THEORA_fuzzer-5737849938247680

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-08-02 21:13:41 +02:00
Peter Ross
43dbdee264 VP4 video decoder 2019-06-12 20:06:20 +10:00
Peter Ross
a212c8da48 avcodec/vp3: spin off get_eob_run and get_coeff coeff functions
these reoutines are shared by vp3 and vp4.
2019-06-12 20:06:20 +10:00
Peter Ross
b6ca032ade avcodec/vp3data: combine eob_run_base and eob_run_get_bits tables 2019-06-08 09:37:26 +10:00
Peter Ross
1dfd7aecf2 avcodec/vp3dsp: move vp3 init loop filter function to vp3dsp
This is also used by the VP6 decoder.

Signed-off-by: Peter Ross <pross@xvid.org>
2019-01-26 23:48:34 +11:00
Peter Ross
d52a1be4e3 avcodec/vp3: ref_frame/ref_frames are only required when HAVE_THREADS=1 2019-01-14 07:07:54 +11:00
Michael Niedermayer
4885ff663b avcodec/vp3: reindent unpack_superblocks()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-10-29 17:00:49 +01:00
Michael Niedermayer
b5e7e437f4 avcodec/vp3: Do not recalculate coded_fragment_list for keyframes
This improves decoding speed of keyframes

Fixes: Timeout (102->27sec)
Fixes: 9642/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-6676767875006464

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-10-29 17:00:49 +01:00
Michael Niedermayer
f563180817 avcodec/vp3: Reuse local variable in unpack_superblocks()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-10-29 17:00:49 +01:00
Michael Niedermayer
88e3807aaf avcodec/vp3: Do not initialize unused tables for keyframes in unpack_superblock()
Fixes: Timeout (139sec -> 102sec)
Fixes: 9642/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-6676767875006464

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-10-29 17:00:49 +01:00
Michael Niedermayer
5ee203076f avcodec/vp3: Fix end of bitstream check in unpack_superblocks()
Fixes: regression

Found-by: Frank Liberato <liberato@google.com>
Tested-by: Frank Liberato <liberato@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-02 21:46:40 +02:00
Michael Niedermayer
62f07825ba avcodec/vp3: Check that there will be sufficient input for the coded fragments in unpack_superblocks()
Fixes: Timeout
Fixes: 6292/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-4871218218926080

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-05-13 23:52:16 +02:00
Michael Niedermayer
f2318aee8c avcodec/vp3: Error out on invalid num_coeffs in unpack_vlcs()
This fixes a hypothetical integer overflow

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-02-11 17:20:17 +01:00
Michael Niedermayer
570023eab3 avcodec/vp3: Check eob_run
Fixes: out of array access
Fixes: 5919/clusterfuzz-testcase-minimized-5859311382167552
Fixes: special case for theora (untested due to lack of sample)

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-02-11 03:04:48 +01:00
Martin Vignali
4ada428aae avcodec: remove remaining uses of avcodec_get_chroma_sub_sample
Replace them with av_pix_fmt_get_chroma_sub_sample.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-11-06 19:13:03 -03:00
James Almer
a9a6d51ca4 avcodec/theora: export cropping information instead of handling it internally
This merges commit 1202b71269 from libav,
originally written by Anton Khirnov and skipped in
fc63d5ceb3.

 libavcodec/vp3.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
2017-05-26 11:15:45 -03:00
Michael Niedermayer
2f00300b77 avcodec/vp3: Check remaining bits in unpack_dct_coeffs()
Decreases the time spend decoding junk.

May fix: 1283/clusterfuzz-testcase-minimized-6221126759874560

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-01 18:48:39 +02:00
Michael Niedermayer
d8094a303b avcodec/vp3: Do not return random positive values but the buf size
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-03-03 17:17:53 +01:00
Clément Bœsch
8ef57a0d61 Merge commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb'
* commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb':
  cosmetics: Fix spelling mistakes

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-21 21:55:34 +02:00
Vittorio Giovara
41ed7ab45f cosmetics: Fix spelling mistakes
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2016-05-04 18:16:21 +02:00
Michael Niedermayer
18268f761b avcodec/vp3: Fix "runtime error: left shift of negative value"
Fixes: 5c6129154b356b80bcab86f9e3ee5d29/signal_sigabrt_7ffff6ae7cc9_7322_d26ac6d7cb6567db1b8be0159b387d0b.ogg

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-04 13:37:00 +01:00
Michael Niedermayer
26379d4fdd avcodec/vp3: ensure header is parsed successfully before tables
Fixes assertion failure
Fixes: 266ee543812e934f7b4a72923a2701d4/signal_sigabrt_7ffff6ae7cc9_7322_85218d61759d461bdf7387180e8000c9.ogg

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-03 00:13:27 +01:00
Michael Niedermayer
a814f1d364 avcodec/vp3: always set pix_fmt in theora_decode_header()
Fixes assertion failure
Fixes: d0bb0662da342ec65f8f2a081222e6b9/signal_sigabrt_7ffff6ae7cc9_5471_82964f0a9ac2f4d3d59390c15473f6f7.ogg

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-11-30 04:25:00 +01:00
Michael Niedermayer
861f2b2a53 avcodec/vp3: Fix several memleaks
Fixes: 1536b9b096a8f95b742bae9d3d761cc6/signal_sigsegv_294aaed_4460_b209bd1e7cebe458b53072a44191316d.ogg

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-11-28 01:01:41 +01:00