Commit Graph

109 Commits

Author SHA1 Message Date
Michael Niedermayer a5d1497f33
avformat/concatdec: Check file
Fixes: null pointer dereference
Fixes: -stream_loop 1 -ss 00:00:05 -i zgclab/ffmpeg_crash/poc2 -codec:v copy -codec:a aac -y output.mp4

Found-by: Wang Dawei and Zhou Geng, from Zhongguancun Laboratory
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-09 16:17:39 +02:00
Andreas Rheinhardt 790f793844 avutil/common: Don't auto-include mem.h
There are lots of files that don't need it: The number of object
files that actually need it went down from 2011 to 884 here.

Keep it for external users in order to not cause breakages.

Also improve the other headers a bit while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-31 00:08:43 +01:00
Michael Niedermayer 007486058c
avformat/concatdec: Check user_duration sum
Fixes: 62276/clusterfuzz-testcase-minimized-ffmpeg_dem_CONCAT_fuzzer-6434245599690752
Fixes: signed integer overflow: 9223372026773000000 + 22337000000 cannot be represented in type 'long'

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-03-26 23:25:35 +01:00
Andreas Rheinhardt 4a4dcde339 avformat/internal: Move FF_FMT_INIT_CLEANUP to demux.h
and rename it to FF_INFMT_INIT_CLEANUP. This flag is demuxer-only,
so this is the more appropriate place for it.
This does not preclude adding internal flags common to both
demuxer and muxer in the future.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-26 06:36:43 +01:00
Michael Niedermayer dd733b2be4
avformat/concatdec: clip outpoint - inpoint overflow in get_best_effort_duration()
An alternative would be to limit all time/duration fields to below 64bit

Fixes: signed integer overflow: -93000000 - 9223372036839000000 cannot be represented in type 'long long'
Fixes: 64546/clusterfuzz-testcase-minimized-ffmpeg_dem_CONCAT_fuzzer-5110813828186112

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-03-26 01:19:17 +01:00
Michael Niedermayer b2d7cbc378
avformat/concatdec: Check in and outpoints to be to produce a positive representable duration
Fixes: signed integer overflow: -93000000 - 9223372036839000000 cannot be represented in type 'long'
Fixes: 64546/clusterfuzz-testcase-minimized-ffmpeg_dem_CONCAT_fuzzer-5110813828186112

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-03-10 19:49:04 +01:00
Andreas Rheinhardt b800327f4c avformat/avformat: Add FFInputFormat, hide internals of AVInputFormat
This commit does for AVInputFormat what commit
59c9dc82f4 did for AVOutputFormat:
It adds a new type FFInputFormat, moves all the internals
of AVInputFormat to it and adds a now reduced AVInputFormat
as first member.

This does not affect/improve extensibility of both public
or private fields for demuxers (it is still a mess due to lavd).

This is possible since 50f34172e0
(which removed the last usage of an internal field of AVInputFormat
in fftools).

(Hint: tools/probetest.c accesses the internals of FFInputFormat
as well, but given that it is a testing tool this is not considered
a problem.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-07 08:53:31 -03:00
Anton Khirnov 08bebeb1be Revert "all: Don't set AVClass.item_name to its default value"
Some callers assume that item_name is always set, so this may be
considered an API break.

This reverts commit 0c6203c97a.
2024-01-20 10:34:48 +01:00
Andreas Rheinhardt 0c6203c97a all: Don't set AVClass.item_name to its default value
Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9;
also avoids relocations.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-12-22 15:12:33 +01:00
James Almer 5432d2aaca avformat/avformat: use the side data from AVStream.codecpar
Deprecate AVStream.side_data and its helpers in favor of the AVStream's
codecpar.coded_side_data.

This will considerably simplify the propagation of global side data to decoders
and from encoders. Instead of having to do it inside packets, it will be
available during init().
Global and frame specific side data will therefore be distinct.

Signed-off-by: James Almer <jamrial@gmail.com>
2023-10-06 10:03:57 -03:00
Michael Niedermayer dedc78b4b5
avformat/concatdec: Check in/outpoint for overflow
Fixes: signed integer overflow: 91542414454000000 - -9154241494546000000 cannot be represented in type 'long'
Fixes: 51896/clusterfuzz-testcase-minimized-ffmpeg_dem_CONCAT_fuzzer-4739147999084544

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>
2023-10-03 20:09:27 +02:00
James Almer 63db6a02a7 avformat/concatdec: check that there's extradata before trying to copy it
The first argument for memcpy must not be NULL.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-11-17 10:53:20 -03:00
Andreas Rheinhardt 2b41463b87 avformat/internal: Don't include avcodec.h
The general demuxing API uses parsers and decoders. Therefore
FFStream contains pointers to AVCodecContexts and
AVCodecParserContext and lavf/internal.h includes lavc/avcodec.h.

Yet actually only a few files files really use these; and it is best
when this number stays small. Therefore this commit uses opaque
structs in lavf/internal.h for these contexts and stops including
avcodec.h.
This also avoids including lavc/codec_desc.h implicitly. All other
headers are implicitly included as now (mostly through codec.h).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-26 03:02:50 +02:00
Andreas Rheinhardt 35ec5c819b avformat/demux: Add new demux.h header
And move those stuff already in demuxer-only files to it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:37:38 +02:00
Pierre-Anthony Lemieux 2a1eae2179
avformat/concat: refactor to use ff_rescale_interval()
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2022-03-19 21:34:08 +10:00
Gerard Sole 18ad360648 libavformat: add side_data copy in concat demuxer
Adds support for concat demuxer to copy the side data information
from the input file to the resulting file. It will behave like the
metadata copy, where the metadata of the first file is kept in the
the output file.

Extract the current code that already performs the stream side_data
copy into a separate method and reuse the method in the concat demuxer.

Signed-off-by: Gerard Sole <g.sole.ca@gmail.com>
2021-12-22 12:05:41 +01:00
Googleplex 23a1f11d02 avformat/concatdec: fix NEEDS_UNSAFE flag value
NEEDS_UNSAFE has the same value as NEEDS_FILE,
causing "duration not allowed if safe" error
while duration directive doesn't require unsafe mode.

Signed-off-by: Googleplex <yyoung2001@gmail.com>
2021-11-14 19:25:11 +01:00
Michael Niedermayer 0b761e87c0 avformat/concatdec: Use FAIL() macro instead of direct return in concat_parse_script()
Fixes: memleak
Fixes: 38893/clusterfuzz-testcase-minimized-ffmpeg_dem_CONCAT_fuzzer-4785231933079552

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-22 18:53:53 +02:00
Andreas Rheinhardt 40bdd8cc05 avformat: Avoid allocation for AVStreamInternal
Do this by allocating AVStream together with the data that is
currently in AVStreamInternal; or rather: Put AVStream at the
beginning of a new structure called FFStream (which encompasses
more than just the internal fields and is a proper context in its own
right, hence the name) and remove AVStreamInternal altogether.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-17 13:22:25 +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
Nicolas George 0210c8fee2 lavf/concatdec: support per-file options 2021-08-22 11:44:16 +02:00
Nicolas George 46fb395952 libavformat/concatdec: remove support for unsafe=-1
It only makes sense as the default value,
but it is not the default since 689211d572.
2021-08-22 11:44:16 +02:00
Andreas Rheinhardt fd101c9c3b avformat/internal: Move ff_read_line_to_bprint_overwrite to avio_internal.h
It only uses an AVIOContext and an AVBPrint.

When doing so, it turned out that several non-users of
ff_read_line_to_bprint_overwrite() and ff_bprint_to_codecpar_extradata()
relied on libavformat/internal.h to include bprint.h or avstring.h
for them. In order to avoid a repeat of this and in order to reduce
unnecessary dependencies, a forward declaration of struct AVBPrint is
used instead of including bprint.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-29 22:02:05 +02:00
Andreas Rheinhardt 2934a4b9a5 Remove unnecessary avassert.h inclusions
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-22 15:02:30 +02:00
Andreas Rheinhardt 57b5ec6ba7 avcodec/avcodec: Stop including bsf.h in avcodec.h
Also include bsf.h directly wherever it is used.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-22 11:14:16 +02:00
Andreas Rheinhardt 2ca36ef08b avformat/concatdec: Simplify cleanup after read_header failure
by setting the FF_FMT_INIT_CLEANUP flag.

(Btw: concat_read_close() is not idempotent (it frees cat->files, but
doesn't reset cat->nb_files), so this demuxer was incompatible with
simply calling read_close generically upon read_header failure.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-07 21:47:20 +02:00
James Almer 591b88e678 avformat: move AVStream.{first,cur}_dts to AVStreamInternal
They are private fields, no reason to have them exposed in a public header.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-06-09 13:55:25 -03:00
Andreas Rheinhardt bc70684e74 avformat: Constify all muxer/demuxers
This is possible now that the next-API is gone.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 11:48:06 -03:00
Andreas Rheinhardt ef6a9e5e31 avutil/buffer: Switch AVBuffer API to size_t
Announced in 14040a1d91.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:13 -03:00
Andreas Rheinhardt a46d781905 avcodec/packet: Also change av_packet_pack/unpack_dictionary to size_t
These are auxiliary side-data functions, so they should have been
switched to size_t in d79e0fe65c,
but this has been forgotten.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-19 03:12:24 +01:00
Michael Niedermayer 2610acb49a avformat/concatdec: use av_strstart()
Fixes: out array read
Fixes: 26610/clusterfuzz-testcase-minimized-ffmpeg_dem_CONCAT_fuzzer-5631838049271808

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-11-03 00:46:59 +01:00
Andreas Rheinhardt be22f97332 avformat/concatdec: Avoid duplicating buffer when adding side-data
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-05-28 12:01:22 +02:00
Andreas Rheinhardt 6a67d518d6 avformat: Remove unnecessary av_packet_unref()
Since bae8844e the packet will always be unreferenced when a demuxer
returns an error, so that a lot of calls to av_packet_unref() in lots of
demuxers are now redundant and can be removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-02-10 22:41:38 +01:00
Andreas Rheinhardt 82d61a9ce3 avformat: Don't free old extradata before ff_alloc/get_extradata
These functions already free it themselves before they allocate the new
extradata.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-12-12 19:25:33 +01:00
Carl Eugen Hoyos 4d8875ec23 lavf: Constify the probe function argument.
Reviewed-by: Lauri Kasanen
Reviewed-by: Tomas Härdin
2019-03-21 11:42:17 +01:00
Marton Balint 1b126ec408 avformat/concatdec: always re-calculate start time and duration
This allows the underlying files to change their duration on subsequent
avformat context opens.

An example use case where this matters:

ffconcat version 1.0
file dummy.mxf
file dummy.mxf

ffmpeg -re -stream_loop -1 -i dummy.ffconcat -f sdl2 none

The user can seamlessly change the input by atomically replacing dummy.mxf.

v2: Set ConcatFile duration in read_header for all segments with known
durations because from now on we always recalculate the start time in
open_file, and an instant seek could have caused unset ConcatFile durations.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-01-22 20:14:11 +01:00
Marton Balint 679cbd8f18 avformat/concatdec: fix cur_dts based duration calculation with nonzero stream start_time
Signed-off-by: Marton Balint <cus@passwd.hu>
2019-01-22 20:14:11 +01:00
Marton Balint 0a98622cbe avformat/concatdec: factorize the duration calculating function
Signed-off-by: Marton Balint <cus@passwd.hu>
2019-01-22 20:14:11 +01:00
Marton Balint 7f42276aa9 avformat/concatdec: always allow seeking to start
Signed-off-by: Marton Balint <cus@passwd.hu>
2018-12-30 21:06:19 +01:00
Marton Balint 37d472a906 avformat/concatdec: only set output stream index before returning packet
Fixes ticket #6434.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Marton Balint <cus@passwd.hu>
2018-04-02 20:41:53 +02:00
Marton Balint ffabff1baa avformat/concatdec: add support for very long line sizes
Fixes ticket #6761.

Signed-off-by: Marton Balint <cus@passwd.hu>
2018-02-24 20:21:35 +01:00
Marton Balint 18ac642359 avformat: migrate to AVFormatContext->url
Signed-off-by: Marton Balint <cus@passwd.hu>
2018-01-28 23:06:43 +01:00
Nicolas George e45f7bca73 lavf/concatdec: properly init streams timestamp parameters.
pts_wrap_bits defaults to 33 (like MPEG), that causes valid
timestamps to be unwrapped and become invalid.
Inspired by a patch by Wu Zhiqiang <mymoeyard@gmail.com>.
2017-12-31 10:33:24 +01:00
Justin Ruggles 1a0d9b503d avformat/concatdec: add fallback for calculating file duration
If a file does not have a known duration, this leads to the timestamps
starting over for the next file, causing non-monotonic timestamps.
To prevent this, track the duration during demuxing and use it to
determine the current file duration before opening the next file.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2017-08-31 15:33:52 +01:00