Commit Graph

24046 Commits

Author SHA1 Message Date
Andreas Rheinhardt dfbf41775c avformat/mux, mxfenc, utils: Use dedicated pointer for AVFormatInternal
This gets rid of ugly "->internal" and is in preparation for removing
AVFormatInternal altogether.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-17 04:43:04 +02:00
Andreas Rheinhardt eaacb5c513 avformat/asfenc, mux, utils: Use smaller scope for variables
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-17 04:17:25 +02:00
Andreas Rheinhardt 8ab5bf512a avformat/mp3dec: Simplify checking for no-metadata
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-17 04:15:56 +02:00
Andreas Rheinhardt 6d1e792980 avformat/mp3dec: Avoid calling avio_tell() multiple times
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-17 04:14:25 +02:00
James Almer 229e949c8e avformat/mvdec: Don't signal success on parse_audio_var() error
Propagate the error it returned instead.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-09-16 19:44:32 -03:00
Michael Niedermayer 737e6bf216 avformat/mvdec: Do not set invalid sample rate
Fixes: signed integer overflow: -682581959642593728 * 16 cannot be represented in type 'long'
Fixes: 37883/clusterfuzz-testcase-minimized-ffmpeg_dem_MV_fuzzer-5311691517198336

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-09-16 18:41:10 +02:00
Michael Niedermayer f624c92d4c avformat/sbgdec: Check for t0 overflow in expand_tseq()
Fixes: signed integer overflow: 4611686025627387904 + 4611686025627387904 cannot be represented in type 'long'
Fixes: 35489/clusterfuzz-testcase-minimized-ffmpeg_dem_SBG_fuzzer-4862678601433088

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-09-16 18:41:10 +02:00
Nicolas George 94aa7e8a76 lavf/concatdec: add stream_extradata directive 2021-09-16 10:17:59 +02:00
Nicolas George 2263ff505c lavf/concat: add support for chapters 2021-09-16 10:17:59 +02:00
Nicolas George 0a267bc5e2 lavf/concatdec: add stream_codec directive 2021-09-16 10:17:59 +02:00
Nicolas George c753b49c38 lavf/concatdec: support stream metadata 2021-09-16 10:17:59 +02:00
Nicolas George 76cf1ff979 lavf/concat: deprecate file_packet_metadata 2021-09-16 10:17:59 +02:00
Nicolas George 7517777d06 lavf/concat: add file_packet_meta directive
Same as file_packet_metadata without the double parsing.
2021-09-16 10:17:59 +02:00
Nicolas George 74ab93fa7f lavf/concat: refactor parsing 2021-09-16 10:17:59 +02:00
Michael Niedermayer e2c2872393 avformat/rmdec: Use 64bit for intermediate for DEINT_ID_INT4
Fixes: runtime error: signed integer overflow: 65312 * 65535 cannot be represented in type 'int'
Fixes: 32832/clusterfuzz-testcase-minimized-ffmpeg_dem_RM_fuzzer-4817710040088576

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-09-15 19:55:17 +02:00
Michael Niedermayer 2768928624 avformat/sbgdec: Check opt_duration and start for overflow
Fixes: signed integer overflow: 2788626175500000000 + 7118941284000000000 cannot be represented in type 'long'
Fixes: 35215/clusterfuzz-testcase-minimized-ffmpeg_dem_SBG_fuzzer-6123272247836672

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-09-15 14:57:36 +02:00
Michael Niedermayer 9a222f140e avformat/mov: Check for duplicate clli
Fixes: memleak
Fixes: 35261/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-4869656287510528

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-09-14 17:34:33 +02:00
Michael Niedermayer 4d81550df9 avformat/utils: Ignore negative duration in codec_info_duration computation
Fixes: signed integer overflow: -5994697211974418462 + -3255307777713450286 cannot be represented in type 'long'
Fixes: 35332/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-5868035117285376

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-09-14 16:51:29 +02:00
Michael Niedermayer 989febfbd0 avformat/jacosubdec: Check for min in t overflow in get_shift()
Fixes: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
Fixes: 34651/clusterfuzz-testcase-minimized-ffmpeg_dem_JACOSUB_fuzzer-5157941012463616

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-09-13 22:48:10 +02:00
Michael Niedermayer 3dd5a8a135 avformat/mxfdec: check channel number in mxf_get_d10_aes3_packet()
Fixes: Out of array access
Fixes: 37030/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5387719147651072

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-09-13 21:13:05 +02:00
Paul B Mahol d1971d69c7 avformat/dv: always set audio packet duration
If audio packet is present in DV stream it have duration of 1 in DV timebase units.
2021-09-12 22:23:35 +02:00
Andreas Rheinhardt 3008a93b4d avformat/rtpdec: Make ff_rtp_handler_iterate() static
Possible since 6197453761.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-08 22:59:14 +02:00
Andreas Rheinhardt cd3d7b0f8f avformat/rawdec: Make ff_raw_data_read_header() static
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-08 22:59:14 +02:00
Andreas Rheinhardt 49916dafb9 avformat/mov_chan: Make ff_mov_get_channel_layout() static
Possible since 3bab7cd128.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-08 22:59:14 +02:00
Paul B Mahol 7b523a06d0 avformat/dhav: use frame number if timestamp difference is zero 2021-09-08 22:54:55 +02:00
Paul B Mahol 7ebeef6aff avformat/mlpdec: fix time_base for packet timestamps 2021-09-07 18:16:13 +02:00
Peter Ross c655a734b1 avcodec/siren: MSN Siren decoder
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Peter Ross <pross@xvid.org>
2021-09-07 18:07:11 +10:00
Andreas Rheinhardt 2f710734c8 avformat/mux: Fix double-free when using AVPacket.opaque_ref
Up until now, ff_write_chained() copied the packet (manually, not with
av_packet_move_ref()) from a packet given to it to a stack packet whose
timing and stream_index is then modified before being sent to another
muxer via av_(interleaved_)write_frame(). Afterwards it is intended to
sync the fields of the packet relevant to freeing again; yet this only
encompasses buf, side_data and side_data_elems and not the newly added
opaque_ref. The other fields are not synced so that the returned packet
can have a size > 0 and data != NULL despite its buf being NULL (this
always happens in the interleaved codepath; before commit
fe251f77c8 it could also happen in the
noninterleaved one). This leads to double-frees if the interleaved
codepath is used and opaque_ref is set.

This commit therefore changes this by directly reusing the packet
instead of a spare packet. Given that av_write_frame() does not
change the packet given to it, one only needs to restore the timing
information to return it as it was; for the interleaved codepath
it is not possible to do likewise*, because av_interleaved_write_frame()
takes ownership of the packets given to it and returns blank packets.
But precisely because of this users of the interleaved codepath
have no legitimate expectation that their packet will be returned
unchanged. In line with av_interleaved_write_frame() ff_write_chained()
therefore returns blank packets when using the interleaved codepath.

Making the only user of said codepath compatible with this was trivial.

*: Unless one wanted to create a full new reference.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-03 19:23:18 +02:00
Paul B Mahol 11d39873ab avformat/cafdec: try skipping various chunks only when seeking is possible 2021-09-03 01:21:51 +02:00
James Almer 8a6beccf0d avformat: add an AV1 Low overhead bitstream format muxer
Suggested-by: BBB
Signed-off-by: James Almer <jamrial@gmail.com>
2021-09-01 19:55:30 -03:00
Andreas Rheinhardt fea4f953b5 avformat/utils: Use av_memdup to duplicate array of AVChapter *
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-31 17:01:38 +02:00
Andreas Rheinhardt bcbd84f435 avformat/utils: Don't allocate zero-sized array
It is unnecessary and also ill-defined: av_malloc() returns a 1-byte
block of memory in this case, but this is not documented.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-31 17:01:04 +02:00
Andreas Rheinhardt e04ddba64f avformat/utils: Don't compare pointers when sorting chapters
The chapters are independently allocated, so that comparing
the pointers is undefined behaviour. Furthermore, its result
is not platform-independent (and may not even be deterministic
on a particular platform). So compare the chapters' ids instead.
(avpriv_new_chapter() ensures that there are no duplicate ids.)

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-31 17:00:42 +02:00
Andreas Rheinhardt 6e0823ab83 avformat/utils: Allocate AVStream.info only for input streams
This structure is only used for demuxers (mostly in
avformat_find_stream_info()), so only allocate it for them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-30 16:12:22 +02:00
Andreas Rheinhardt 10646d30a3 avformat/utils: Don't initialize AVStreamInternal.info multiple times
It has been allocated and initialized in avformat_find_stream_info()
until fd0368e7ca when the structure
was moved to AVStreamInternal and its allocation to avformat_new_stream.
In order to also initialize the struct for new streams that only get
created during avformat_find_stream_info() said the initialization has
been added to avformat_new_stream() later. Due to the Libav-FFmpeg split
this has been done twice: In 4cda8aa1c5
and in 30c26c2442. The initialization in
avformat_find_stream_info() has not been removed at all despite being
redundant. This commit removes it and the duplicated initialization in
avformat_new_stream().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-30 16:12:22 +02:00
Andreas Rheinhardt 2c3c83663d avformat/utils: Remove redundant flushing of packet queue
The packet queue is already flushed in avformat_free_context() which
is called a few lines below.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-30 16:12:22 +02:00
Andreas Rheinhardt bafb65ba2a avformat/mux: Don't access AVStream's internal AVCodecContext
An AVStream's internal AVCodecContext is pretty much unused for muxing:
The only place where any of its fields are set is
avformat_transfer_internal_stream_timing_info() where its time base is
set based upon the desired output format. The max_b_frames field is
never set at all, so don't read it in mux.c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-30 16:12:22 +02:00
Andreas Rheinhardt c6d780b92e avformat/utils: Make ff_compute_frame_duration() static
Since 1c0885334d ff_compute_frame_duration
is only called from within utils.c and only for demuxers. So make it
static and remove the code in it that deals with muxers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-30 16:12:22 +02:00
Andreas Rheinhardt 3f991325b5 avformat/utils: Remove obsolete todo
Also initialize the AVCodecContexts directly.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-30 16:12:22 +02:00
Andreas Rheinhardt f265374bc0 avformat/utils: Remove always-false check
AVFormatContext.internal is already allocated by
avformat_alloc_context() on success; and on error,
avformat_alloc_context() cleans up manually without
avformat_free_context().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-30 16:12:22 +02:00
Andreas Rheinhardt 9abf0e0419 avformat/yuv4mpegdec: Don't call avio_tell() twice
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-30 15:48:11 +02:00
Andreas Rheinhardt b2d61d0f02 avformat/matroskadec: Fix heap-buffer overflow upon gigantic timestamps
The WebM DASH Manifest demuxer creates a comma-delimited list of
all the timestamps of index entries. It allocates 20 bytes per
timestamp; yet the largest 64bit numbers have 20 decimal digits
(for int64_t it can be '-'+ 19 digits), so that one needs 21B
per entry because of the comma (resp. the final NUL).

The code uses snprintf, but snprintf returns the strlen of the string
that would have been written had the supplied buffer been big enough.
And if this is 21, then the next entry is written at an offset of 21
from the current position. So if enough such entries exist, the buffer
won't suffice.

This commit fixes this by replacing the allocation of buffer for
the supposedly worst-case with dynamic allocations by using an AVBPrint.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-30 15:48:11 +02:00
Michael Niedermayer 4de4bc06fd avformat/mov: Check dts for overflow in mov_read_trun()
Fixes: signed integer overflow: 9223372034248226491 + 3275247799 cannot be represented in type 'long'
Fixes: clusterfuzz-testcase-minimized-audio_decoder_fuzzer-4538729166077952

Reported-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-08-29 21:34:38 +02:00
Michael Niedermayer a4c98c507e avformat/avidec: Use 64bit for frame number in odml index parsing
Fixes: signed integer overflow: 1179337772 + 1392508928 cannot be represented in type 'int'
Fixes: 34088/clusterfuzz-testcase-minimized-ffmpeg_dem_AVI_fuzzer-5846945303232512

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-08-28 20:47:24 +02:00
Andreas Rheinhardt 0871273a2f avformat/flac_picture: Reindentation
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-28 15:25:18 +02:00
Andreas Rheinhardt e304f5f758 avformat/flac_picture: Simplify parsing title
Don't allocate the buffer for the title ourselves, leave it to
av_dict_set(). This simplifies freeing.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-28 15:25:18 +02:00
Andreas Rheinhardt c1f4858242 avformat/flac_picture: Try to reuse buffer for attached picture
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-28 15:25:18 +02:00
Andreas Rheinhardt b10a8a30db avformat/oggparsevorbis: Avoid tmp bufs when parsing VorbisComment
A single VorbisComment consists of a length field and a
non-NUL-terminated string of the form "key=value". Up until now,
when parsing such a VorbisComment, zero-terminated duplicates of
key and value would be created. This is wasteful if these duplicates
are freed shortly afterwards, as happens in particular in case of
attached pictures: In this case value is base64 encoded and only
needed to decode the actual data.

Therefore this commit changes this: The buffer is temporarily modified
so that both key and value are zero-terminated. Then the data is used
in-place and restored to its original state afterwards.

This requires that the buffer has at least one byte of padding. All
buffers currently have AV_INPUT_BUFFER_PADDING_SIZE bytes padding,
so this is ok.

Finally, this also fixes weird behaviour from ogm_chapter():
It sometimes freed given to it, leaving the caller with dangling
pointers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-28 15:25:18 +02:00
Andreas Rheinhardt f1d89d6dd0 avformat/oggparsevorbis: Factor parsing a single VorbisComment out
This is in preparation for further commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-28 15:25:18 +02:00
Andreas Rheinhardt 831718bbab avformat/movenc: Avoid calling strlen multiple times
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-27 10:47:35 +02:00