]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/avpacket: Always treat dst in av_packet_ref as uninitialized
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Wed, 12 Feb 2020 11:18:23 +0000 (12:18 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 28 Mar 2020 02:54:48 +0000 (03:54 +0100)
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>
libavcodec/avcodec.h
libavcodec/avpacket.c

index 78c483c25c5ff6afa99f5eef8b3b427e12116f39..f918d20a61561b7a990baa696b3911b58527b412 100644 (file)
@@ -4648,7 +4648,7 @@ void av_packet_free_side_data(AVPacket *pkt);
  *
  * @see av_packet_unref
  *
- * @param dst Destination packet
+ * @param dst Destination packet. Will be completely overwritten.
  * @param src Source packet
  *
  * @return 0 on success, a negative AVERROR on error.
index b5667659fd09fdd5e4a905b42c300dda5aab0efb..132567bc2d4a13dbfd683d3af7ae63b6f551c451 100644 (file)
@@ -615,6 +615,7 @@ int av_packet_ref(AVPacket *dst, const AVPacket *src)
         return ret;
 
     if (!src->buf) {
+        dst->buf = NULL;
         ret = packet_alloc(&dst->buf, src->size);
         if (ret < 0)
             goto fail;