]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/avpacket: Don't write into non-writable buffer
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Wed, 12 Feb 2020 12:27:17 +0000 (13:27 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 30 Apr 2020 07:02:27 +0000 (09:02 +0200)
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>
libavcodec/avpacket.c

index 55b509108eb6c98a7f01f054e2dcce34d429e014..ee51c0799cacff2f3293a341b98b064947d4f763 100644 (file)
@@ -128,7 +128,8 @@ int av_grow_packet(AVPacket *pkt, int grow_by)
                 return AVERROR(ENOMEM);
         }
 
-        if (new_size + data_offset > pkt->buf->size) {
+        if (new_size + data_offset > pkt->buf->size ||
+            !av_buffer_is_writable(pkt->buf)) {
             int ret = av_buffer_realloc(&pkt->buf, new_size + data_offset);
             if (ret < 0) {
                 pkt->data = old_data;