[FFmpeg-devel] [PATCH 3/3] avcodec/avpacket: Don't write into	non-writable buffer
    Andreas Rheinhardt 
    andreas.rheinhardt at gmail.com
       
    Wed Feb 12 17:31:27 EET 2020
    
    
  
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 at gmail.com>
---
 libavcodec/avpacket.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 0d9ddeee07..a7b0b6bd5d 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -127,7 +127,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;
-- 
2.20.1
    
    
More information about the ffmpeg-devel
mailing list