Commit Graph

544 Commits

Author SHA1 Message Date
Michael Niedermayer 20a6bfda0f
avformat/mxfdec: Check body_offset
Fixes: signed integer overflow: 538976288 - -9223372036315799520 cannot be represented in type 'long'
Fixes: 68060/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-5523457266745344

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Tomas Härdin <git@haerdin.se>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-01 02:57:12 +02:00
Michael Niedermayer ed49391961
avformat/mxfdec: Check index_edit_rate
Fixes: Assertion b >=0 failed at libavutil/mathematics.c:62
Fixes: 67811/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-5108429687422976

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-04-04 19:38:29 +02:00
Michael Niedermayer f30fe5e8d0
avformat/mxfdec: Make edit_unit_byte_count unsigned
Suggested-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-04-01 18:52:38 +02:00
Michael Niedermayer d6ed6f6e8d
avformat/mxfdec: Check first case of offset_temp computation for overflow
This is kind of ugly
Fixes: signed integer overflow: 255 * 1157565362826411919 cannot be represented in type 'long'
Fixes: 67313/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-6250434245230592

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-04-01 18:17:28 +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
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
Marton Balint d35b6fda45 avformat/mxfdec: signal channel layouts using the new channel layout api
Signed-off-by: Marton Balint <cus@passwd.hu>
2024-03-16 19:49:39 +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
Marton Balint 4ebf478f4c avformat/mxfdec: track metadata sets by their type
We typically are only interesed in a single type of metadata set, so it is
better to keep them separated instead of always filtering for them.

Also use av_dynarray_add for increasing their array.

Signed-off-by: Marton Balint <cus@passwd.hu>
2024-03-02 18:49:31 +01:00
Marton Balint aa299faa9a avformat/mxfdec: remove resolve_strong_ref usage with AnyType
UUIDs do not have to be unique if their type sets them apart, so avoid using
AnyType, since we are only interested in specific types.

Signed-off-by: Marton Balint <cus@passwd.hu>
2024-03-02 18:49:31 +01:00
Marton Balint 68f2b32ef2 avformat/mxfdec: do not use AnyType when resolving Descriptors and MultipleDescriptors
By using AnyType for resolving a strong reference we searched among all types,
not just the ones which can be the target of the reference, which in some cases
caused to find the wrong type, if the metadata set UUIDs were not unique.

UUIDs do not have to be unique if their type sets them apart, SMPTE 377M says:

> StrongRef: 'One to One’ relationship between sets and implemented in MXF
> with UUIDs. Strong References are typed which means that the definition
> identifies the kind of set which is the target of the reference.

Fixes ticket #10865.

Signed-off-by: Marton Balint <cus@passwd.hu>
2024-02-20 00:04:40 +01:00
Marton Balint 41672f5586 avformat/mxfdec: move resolving Descriptors to the multi descriptor resolve function
Also remove unused descriptor member from MXFPackage.

Signed-off-by: Marton Balint <cus@passwd.hu>
2024-02-20 00:04:40 +01: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
Michael Niedermayer 70f5fa6325
avformat/mxfdec: Check klv offset
Fixes: Assertion klv_offset >= mxf->run_in failed at libavformat/mxfdec.c:736
Fixes: 62936/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-5778404366221312.fuzz

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Tomas Härdin <git@haerdin.se>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-10-19 20:44:56 +02: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 442d9412d2
avformat/mxfdec: Remove this_partition
Suggested-by: Tomas Härdin <git@haerdin.se>
Fixes: 51896/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-5130394286817280

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-09-29 19:23:36 +02:00
Andreas Rheinhardt 58aaa83fa2 avformat/mxfdec: Don't pretend array to be bigger than it is
mxf_match_uid() accepts two const UID and a len parameter.
UID is a typedef for an array of 16 uint8_t, so the const UID
parameter is actually a pointer to const uint8_t.

The point of mxf_match_uid() is to check whether the initial
part of two UIDs match; the length of said part is given
by the len parameter. Once an incomplete UID has been passed
to mxf_match_uid() (albeit with the correct len, so safe),
which makes GCC emit -Wstringop-overread warnings.

Fix this by using a const uint8_t[] as type; it is more
natural for incomplete UIDs.

Reviewed-by: Tomas Härdin <git@haerdin.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-11 20:27:32 +02:00
Andreas Rheinhardt 8238bc0b5e avcodec/defs: Add AV_PROFILE_* defines, deprecate FF_PROFILE_* defines
These defines are also used in other contexts than just AVCodecContext
ones, e.g. in libavformat. Furthermore, given that these defines are
public, the AV-prefix is the right one, so deprecate (and not just move)
the FF-macros.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-07 00:39:02 +02:00
Andreas Rheinhardt 0c6e5f321b avformat/avformat: Avoid including codec.h, frame.h
AVCodec is only ever used as an incomplete type (i.e. via a pointer
to an AVCodec) in avformat.h and it is not really part of the core
of avformat.h or libavformat; almost none of our internal users
make use of it (and none make use of hwcontext.h, which is implicitly
included). So switch to use struct AVCodec, but continue to include
codec.h for external users for compatibility.

Also, do the same for AVFrame and frame.h, which is implicitly included
by codec.h (via lavu/hwcontext.h).

Also, remove an unnecessary inclusion of <time.h>.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-07 00:30:08 +02:00
Ammon Riley 4373dadc39 avformat/mxfdec: recognize AAC per SMPTE ST 381-4
This patch simply recognizes the AAC audio track during
decode -- it does not add functionality to encode AAC in
MXF.

Signed-off-by: Ammon Riley <ammon.riley@gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2023-05-11 22:37:41 +02:00
Marton Balint 8f534618b5 avformat/mxfdec: treat Random Index Pack as end of file
RIP, if exists is the last KLV item in the MXF files therefore we can stop
parsing the file if it is encountered. This allows us to support files created by
broken muxers such as OpenCube MXFTk Advanced 2.8.0.0.1. which dumps some extra
garbage after the RIP.

Signed-off-by: Marton Balint <cus@passwd.hu>
2023-04-06 00:40:42 +02:00
Marton Balint af606c232a avformat/mxfdec: check number of index table entires more strictly
Let's ignore the index table if the number of index entries does not match the
index duration (or the special AVID index entry counts).

Fixes: OOM
Fixes: 50551/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-6607795234930688

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Marton Balint <cus@passwd.hu>
2023-01-29 18:58:30 +01:00
Marton Balint 41dfa629d7 avformat/mxfdec: support Avid files with an extra index entry
Signed-off-by: Marton Balint <cus@passwd.hu>
2023-01-29 18:58:30 +01:00
Marton Balint 6aff3c5e43 avformat/mxfdec: check index entry array size
Signed-off-by: Marton Balint <cus@passwd.hu>
2023-01-29 18:58:30 +01:00
Michael Niedermayer 64a04fc165
avformat/mxfdec: Use 64bit in remainder
Fixes: signed integer overflow: 48000 * 223587 cannot be represented in type 'int'
Fixes: 54513/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5817594836025344

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Tomas Härdin <git@haerdin.se>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-12-28 00:25:34 +01:00
Gavin Smith 2c2aaa5bd0 avformat/mxfdec: do not log warning of multiple ANC packets if count is 0
Some NLVEs may insert a KLV packet for EIA-608 data even though
the number of encapsulated ANC packets is zero.
2022-10-06 10:23:39 +02:00
Richard Ayres b074424bf6 Encrypted SMPTE DC MXF - additional UL needed to unpack EKLV packet
Thanks, Pierre-Anthony. I've updated the patch to remove the unnecessary UL and it's now using mxf_match_uid() to detect the EKLV packet.

Signed-off-by: Richard Ayres <richard.ayres@bydeluxe.com>
2022-10-06 10:04:17 +02:00
Michael Niedermayer c5bd689655
avformat/mxfdec: Avoid some redundant writing to tables in mxf_compute_ptses_fake_index()
offsets suggested by Tomas Härdin
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-09-22 17:44:04 +02:00
Michael Niedermayer 1182bbb2c3
avformat/mxfdec: only probe max run in
Suggested-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-09-22 17:44:04 +02:00
Michael Niedermayer 7786097825
avformat/mxfdec: Check run_in is within 65536
Fixes: signed integer overflow: 9223372036854775807 - -2146905566 cannot be represented in type 'long'
Fixes: 50993/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-6570996594769920

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-09-22 17:44:03 +02:00
Pierre-Anthony Lemieux 48fa27e77a avformat/mxf: set stream frame rates for ST 422 essence containers
The MXF demuxer does not currently set AVStream::avg_frame_rate and ::r_frame_rate
when J2K essence is wrapped according to SMPTE ST 422.

Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-20 11:25:54 +02:00
Andreas Rheinhardt 04b7217872 avutil/dict: Move avpriv_dict_set_timestamp() to a header of its own
It is used almost nowhere, so it needn't be auto-included
almost everywhere.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-03 15:41:44 +02:00
Michael Niedermayer e6bbaa1d49 avformat/mxfdec: SMPTE RDD 48:2018 Amd 1:2022 support
Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-08-07 22:01:21 +02:00
Andreas Rheinhardt 9ff0fbbc0a avformat/mxfdec: Offload allocating string to av_dict_set()
Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-06-16 18:39:46 +02:00
Andreas Rheinhardt 6b5e3590c7 avformat/mxfdec: Use ff_data_to_hex() for data->hex conversion
In this case it also stops pretending that the length of
the output string is somehow checked (which is currently
being done by using snprintf that is called with the amount
of space needed instead of the amount of space actually available).

Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-06-16 18:39:25 +02:00
Andreas Rheinhardt 8823900b14 avformat/mxfdec: Don't duplicate av_uuid_unparse
Also don't allocate the string ourselves, let av_dict_set()
do it.

Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-06-16 18:39:09 +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
Michael Niedermayer 7aebdb8bf1 avformat/mxfdec: Do not clear array in mxf_read_strong_ref_array() before writing
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-03-21 22:27:14 +01:00
Michael Niedermayer 8d6f49cfc3 avformat/mxfdec: Check for avio_read() failure in mxf_read_strong_ref_array()
Fixes: 42827/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-4900528511909888

Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-03-21 22:27:14 +01:00
Michael Niedermayer 3015c556f3 avformat/mxfdec: Check count in mxf_read_strong_ref_array()
Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-03-21 22:27:14 +01:00
Vittorio Giovara d219681a52 mxf: convert to new channel layout API
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-15 09:42:35 -03:00
Marc-Antoine Arnaud 47c4df2203 avformat/mxfdec: support MCA audio information
Channel reordering is removed from this patch because the new channel layout
API will support it properly.

Signed-off-by: Marton Balint <cus@passwd.hu>
2022-01-09 18:13:53 +01:00
Michael Niedermayer 4f44a218e5 avformat/mxfdec: Check for duplicate mxf_read_index_entry_array()
Fixes: memleak
Fixes: 41596/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-6439060204290048

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-12-09 13:40:54 +01:00
Michael Niedermayer a4af92d7cb avformat/mxfdec: Check component_depth in mxf_get_color_range()
Fixes: shift exponent 4294967163 is too large for 32-bit type 'int'
Fixes: 41449/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-6183636217495552

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-12-09 13:12:45 +01:00
Marc-Antoine Arnaud 447cf53774 avformat/mxfdec: rename sub_descriptors as file_descriptors
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-09-22 22:44:30 +02:00
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 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
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
Marton Balint f0d4077c53 avformat/mxfdec: store parition score instead of partition pointer in metadata
Partition struct may be reallocated, so let's store the score directly in order
to avoid use-after-free.

Also mxf->current_partition might be null when reading some local tags.

Signed-off-by: Marton Balint <cus@passwd.hu>
2021-08-14 11:19:39 +02:00