1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-12 19:18:44 +02:00
Commit Graph

134 Commits

Author SHA1 Message Date
Andreas Rheinhardt
8f51a89d66 avcodec/avpacket: Don't write into non-writable buffer
The data of an AVPacket may be a part of the data of an AVBufferRef;
Therefore av_grow_packet() doesn't reallocate if the available space in
the actual buffer is sufficient for the enlargement. But given that it
also zeroes the padding it also needs to make sure that the buffer is
actually writable; this commit implements this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-30 09:02:27 +02:00
Andreas Rheinhardt
6b0c94780d libavcodec/avpacket: Don't simply forward return value of av_dict_set()
The documentation of av_dict_set() states that values >= 0 indicate
success, whereas av_packet_unpack_dictionary() implies that return
values > 0 are impossible. So only forward the return value of
av_dict_set() in av_packet_unpack_dictionary() on error.

(Btw: av_dict_set() does currently not return values > 0.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-23 19:42:03 +02:00
Jun Zhao
0e1db79e37 lavc: add a new sidedata type for DOVI
add a new sidedata type for DOVI.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2020-04-23 08:05:06 +08:00
Anton Khirnov
9875fd24ce avcodec.h: split AVPacket API into its own header 2020-04-10 13:54:03 +02:00
Andreas Rheinhardt
c52ec0367d avcodec/avcodec, avpacket: Return blank packet on av_packet_ref() failure
Up until now, it was completely unspecified what the content of the
destination packet dst was on error. Depending upon where the error
happened calling av_packet_unref() on dst might be dangerous.

This commit changes this by making sure that dst is blank on error, so
unreferencing it again is safe (and still pointless). This behaviour is
documented.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-28 03:59:15 +01:00
Andreas Rheinhardt
e621f2b6cd avcodec/avpacket: Always treat dst in av_packet_ref as uninitialized
av_packet_ref() mostly treated the destination packet dst as uninitialized,
i.e. the destination fields were simply overwritten. But if the source
packet was not reference-counted, dst->buf was treated as if it pointed
to an already allocated buffer (if != NULL) to be reallocated to the
desired size.

The documentation did not explicitly state whether the dst will be treated
as uninitialized, but it stated that if the source packet is not refcounted,
a new buffer in dst will be allocated. This and the fact that the side-data
as well as the codepath taken in case src is refcounted always treated the
packet as uninitialized means that dst should always be treated as
uninitialized for the sake of consistency. And this behaviour has been
explicitly documented.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-03-28 03:54:48 +01:00
vectronic
05d27f342b API: add AV_PKT_DATA_ICC_PROFILE to AVPacketSideDataType
Signed-off-by: vectronic <hello.vectronic@gmail.com>
2020-03-10 15:10:06 +00:00
James Almer
717b2074ec avcodec: add a Producer Reference Time AVPacketSideData type
Signed-off-by: James Almer <jamrial@gmail.com>
2020-01-15 23:33:41 -03:00
Andreas Rheinhardt
e12a2a2d73 avcodec/avpacket: Improve allocating packets
av_mallocz + av_init_packet leads to the same result as av_mallocz +
av_packet_unref, but faster.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-18 22:53:00 +02:00
Jun Zhao
00555f4b8b lavc/avpacket: check NULL before using the pointer
Need to check NULL before using the pointer

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2019-05-12 14:17:22 +08:00
Marton Balint
9f8854cb5a avcodec/avpacket: add some assertions to ensure pkt->data is not null if pkt->size > 0
This should fix the following Coverity false positives:

Coverity CID #1405450.
Coverity CID #1430930.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-03-01 22:32:32 +01:00
Michael Niedermayer
9520d51e21 avcodec/avpacket: Avoid unspecific return -1 for av_grow_packet()
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-01-01 21:11:47 +01:00
Aman Gupta
0c14b73e43 avcodec/avpacket: fix whitespace
Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-10-12 09:48:07 -07:00
Jun Zhao
50d9c85358 lavc/avpacket: Add missing conversions from side data enum to name.
Add missing conversions from side data enum to name.

Signed-off-by: Jun Zhao <mypopydev@gmail.com>
2018-09-21 18:09:37 +08:00
James Almer
860086ee16 avcodec/avpacket: add av_packet_make_refcounted()
It works as a drop in replacement for the deprecated av_dup_packet(),
to ensure a packet is reference counted.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-01 23:40:41 -03:00
James Almer
d205c8f3bb avcodec/avpacket: remove unnecessary check in av_packet_make_writable()
Zero sized packets are already handled below in the function.
This is more in line with av_packet_ref().

Signed-off-by: James Almer <jamrial@gmail.com>
2018-03-27 11:25:57 -03:00
James Almer
f14ca60001 avcodec/avpacket: add av_packet_make_writable()
Useful as well to quickly make a packet reference counted when it
isn't already so.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-03-21 22:17:40 -03:00
Yusuke Nakamura
3b4026e151 avpacket: reset dst side_data fields in av_packet_copy_props
This effectively copies the side data elements from src instead of
potentially merging them with those already existing in dst.
This by extension also removes the only dependency on existing values
in the dst packet.

Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-02-14 20:36:29 -03:00
James Almer
417d473bde avcodec: remove ABI portion of the side data merging API
The actual API is left in place until the deprecation period ends.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-22 00:30:12 -03:00
Karthick J
b6cf66ae1c avdevice/decklink_dec: Added Closed caption decode from VANC
Signed-off-by: Karthick J <kjeyapal@akamai.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2017-09-28 21:06:12 +02:00
James Almer
ecb9741ba2 avcodec/avpacket: deprecate av_copy_packet()
It does the same thing as av_packet_ref().

Signed-off-by: James Almer <jamrial@gmail.com>
2017-09-25 21:22:06 -03:00
Michael Niedermayer
07339a45a0 avcodec/avpacket: Limit iterations in ff_packet_split_and_drop_side_data()
This avoids scaning beyond what a valid packet can contain
Fixes: Timeout
Fixes: 541/clusterfuzz-testcase-610189291657625

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-06-11 22:09:15 +02:00
James Almer
28f60eeabb avcodec/avpacket: allow only one element per type in packet side data
It was never meant to do otherwise, as av_packet_get_side_data() returns the first
entry it finds of a given type.

Based on code from libavformat's av_stream_add_side_data().

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-12 18:30:31 -03:00
Michael Niedermayer
d5711cb891 avcodec/avcodec: Limit the number of side data elements per packet
Fixes: 1293/clusterfuzz-testcase-minimized-6054752074858496

See: [FFmpeg-devel] [PATCH] avcodec/avcodec: Limit the number of side data elements per packet

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-12 14:19:52 +02:00
Michael Niedermayer
e813df4fa3 avcodec: Avoid splitting side data repeatedly
Fixes Timeout
Fixes: 508/clusterfuzz-testcase-6245747678773248

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-06 03:54:17 +02:00
Steve Lhomme
157e57a181 lavc: Add Content Light Level side metadata found in HEVC
These data are necessary when transmitting HDR over HDMI.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-04-06 11:38:15 -03:00
Clément Bœsch
507a85b93c Merge commit 'adb0e941c329a4778ade6dd0a326274472992f54'
* commit 'adb0e941c329a4778ade6dd0a326274472992f54':
  avpacket: Mark src pointer as constant

See 5bb3f88255

Merged-by: Clément Bœsch <u@pkh.me>
2017-04-01 18:23:21 +02:00
wm4
d682ae70b4 avcodec, avformat: deprecate anything related to side data merging
This patch deprecates anything that has to do with merging/splitting
side data. Automatic side data merging (and splitting), as well as all
API symbols involved in it, are removed completely.

Two FF_API_ defines are dedicated to deprecating API symbols related to
this: FF_API_MERGE_SD_API removes av_packet_split/merge_side_data in
libavcodec, and FF_API_LAVF_KEEPSIDE_FLAG deprecates
AVFMT_FLAG_KEEP_SIDE_DATA in libavformat.

Since it was claimed that changing the default from merging side data to
not doing it is an ABI change, there are two additional FF_API_ defines,
which stop using the side data merging/splitting by default (and remove
any code in avformat/avcodec doing this): FF_API_MERGE_SD in libavcodec,
and FF_API_LAVF_MERGE_SD in libavformat.

It is very much intended that FF_API_MERGE_SD and FF_API_LAVF_MERGE_SD
are quickly defined to 0 in the next ABI bump, while the API symbols are
retained for a longer time for the sake of compatibility.
AVFMT_FLAG_KEEP_SIDE_DATA will (very much intentionally) do nothing for
most of the time it will still be defined. Keep in mind that no code
exists that actually tries to unset this flag for any reason, nor does
such code need to exist. Code setting this flag explicitly will work as
before. Thus it's ok for AVFMT_FLAG_KEEP_SIDE_DATA to do nothing once
side data merging has been removed from libavformat.

In order to avoid that anyone in the future does this incorrectly, here
is a small guide how to update the internal code on bumps:

- next ABI bump (probably soon):
  - define FF_API_LAVF_MERGE_SD to 0, and remove all code covered by it
  - define FF_API_MERGE_SD to 0, and remove all code covered by it
- next API bump (typically two years in the future or so):
  - define FF_API_LAVF_KEEPSIDE_FLAG to 0, and remove all code covered
    by it
  - define FF_API_MERGE_SD_API to 0, and remove all code covered by it

This forces anyone who actually wants packet side data to temporarily
use deprecated API to get it all. If you ask me, this is batshit fucked
up crazy, but it's how we roll. Making AVFMT_FLAG_KEEP_SIDE_DATA to be
set by default was rejected as an ABI change, so I'm going all the way
to get rid of this once and for all.

Reviewed-by: James Almer <jamrial@gmail.com>
Reviewed-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
2017-03-21 06:13:45 +01:00
Carl Eugen Hoyos
0d34dbc272 lavc/avpacket: Make pkt parameter of av_packet_get_side_data() const.
Reflects the actual code and silences a gcc warning:
libavcodec/utils.c:2102:36: warning: passing argument 1 of 'av_packet_get_side_data' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
2017-03-16 21:09:41 +01:00
Michael Niedermayer
2c00b37302 avcodec/avpacket: Check metadata key in av_packet_unpack_dictionary()
Fixes timeout
Fixes: 501/clusterfuzz-testcase-5672752870588416

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-03-01 14:07:33 +01:00
Carl Eugen Hoyos
1d54be2153 lavc/avpacket: Initialize a variable in error path.
Fixes ticket #6153.

Tested-by: Tyson Smith
2017-02-17 10:31:29 +01:00
Vittorio Giovara
e7a6f8c972 lavc: Add spherical packet side data API
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2016-12-07 14:40:06 -05:00
James Almer
574929d8b6 avcodec/avpacket: fix leak on realloc in av_packet_add_side_data()
If realloc fails, the pointer is overwritten and the previously allocated
buffer is leaked, which goes against the expected behavior of keeping the
packet unchanged in case of error.

Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-11-19 20:23:25 -03:00
Luca Barbato
adb0e941c3 avpacket: Mark src pointer as constant 2016-11-17 19:41:12 +01:00
Carl Eugen Hoyos
c54eef46f9 lavc/avpacket: Fix undefined behaviour, do not pass a null pointer to memcpy().
Fixes ticket #5857.
2016-09-22 08:37:46 +02:00
Michael Niedermayer
5e1bf9d8c0 avcodec/avpacket: clear side_data_elems
Fixes null pointer dereference

Found-by: 连一汉 <lianyihan@360.cn>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-09-12 23:53:07 +02:00
Carl Eugen Hoyos
f077ad69c6 lavc/avpacket: Fix undefined behaviour, do not pass a null pointer to memcpy().
Fixes ticket #5128.
2016-09-05 10:16:03 +02:00
Clément Bœsch
17fdffc9f8 Merge commit '8996515b137f962e3a8691241c285c96437b6c53'
* commit '8996515b137f962e3a8691241c285c96437b6c53':
  avpacket: fix setting AVPacket.data in av_packet_ref()

This commit is a noop, see ed3a02547c

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-22 19:32:00 +02:00
Vittorio Giovara
05a4bacbf7 avpacket: Error out when creating 0-sized side data
This mimics the behaviour of other av_*_new_side_data().
This is not caught by the malloc check, since padding
is always added to the allocated size.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2016-06-13 13:31:21 -04:00
Andriy Lysnevych
2fe04630e7 avcodec/avpacket: Respect payload offset in av_grow_packet
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-06-02 00:52:22 +02:00
Anton Khirnov
8996515b13 avpacket: fix setting AVPacket.data in av_packet_ref()
The data field does not necessarily point to the beginning of the
underlying AVBuffer.

CC: libav-stable@libav.org
2016-05-16 10:31:08 +02:00
Andriy Lysnevych
ed3a02547c avcodec/avpacket: Respect payload offset in av_packet_ref
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-05-13 03:49:26 +02:00
Michael Niedermayer
9f36ea57ae avcodec/avpacket: Fix off by 5 error
Fixes out of array read
Fixes: mozilla bug 1266129
Found-by: Tyson Smith
Tested-by: Tyson Smith
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-04-21 00:52:40 +02:00
Derek Buitenhuis
9a98ddcf1b Merge commit 'dbb43b8b83b097585ec255ec638b61e359ebea77'
* commit 'dbb43b8b83b097585ec255ec638b61e359ebea77':
  avpacket: properly reset data/size in av_packet_move_ref()

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-04-12 15:39:10 +01:00
Anton Khirnov
dbb43b8b83 avpacket: properly reset data/size in av_packet_move_ref()
It currently just calls av_init_packet(), which does not touch those
fields.
2016-02-26 09:15:36 +01:00
Neil Birkbeck
ad17b9d2d4 libavcodec:add packet level support for mastering metadata
Some containers, like webm/mkv, will contain this mastering metadata.
This is analogous to the way 3D fpa data is handled (in frame and
packet side data).

Signed-off-by: Neil Birkbeck <neil.birkbeck@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-02-25 00:18:12 +01:00
Stefano Sabatini
14f7a3d55a lavc/lavf: transmit stream_id information for mpegts KLV data packets
This allows to copy information related to the stream ID from the demuxer
to the muxer, thus allowing for example to retain information related to
synchronous and asynchronous KLV data packets. This information is used
in the muxer when remuxing to distinguish the two kind of packets (if the
information is lacking, data packets are considered synchronous).

The fate reference changes are due to the use of
av_packet_merge_side_data(), which increases the size of the output
packet size, since side data is merged into the packet data.
2016-02-23 18:44:12 +01:00
Andreas Cadhalpun
fa463aa83a avpacket: fix size check in packet_alloc
The previous check only caught sizes from -AV_INPUT_BUFFER_PADDING_SIZE
to -1.

This fixes ubsan runtime error: signed integer overflow: 2147483647 + 32
cannot be represented in type 'int'

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2016-01-07 08:20:21 +01:00
Andreas Cadhalpun
da3c3c446c avpacket: fix size check in packet_alloc
The previous check only caught sizes from -AV_INPUT_BUFFER_PADDING_SIZE
to -1.

This fixes ubsan runtime error: signed integer overflow: 2147483647 + 32
cannot be represented in type 'int'

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2016-01-05 22:30:50 +01:00
Hendrik Leppkes
74b8fa103d Merge commit '68e547ae8b455e5e2b60839f35c359d77a6d94bc'
* commit '68e547ae8b455e5e2b60839f35c359d77a6d94bc':
  avpacket: use ERANGE instead of EOVERFLOW

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-12-17 14:52:28 +01:00