From patchwork Tue Feb 21 23:14:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 2633 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.149 with SMTP id x21csp615905vsf; Tue, 21 Feb 2017 15:14:52 -0800 (PST) X-Received: by 10.223.164.211 with SMTP id h19mr9388035wrb.75.1487718891985; Tue, 21 Feb 2017 15:14:51 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b141si18084821wma.133.2017.02.21.15.14.51; Tue, 21 Feb 2017 15:14:51 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6F3D3688319; Wed, 22 Feb 2017 01:14:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E05D46882E7 for ; Wed, 22 Feb 2017 01:14:34 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 1BAD9100C20; Wed, 22 Feb 2017 00:14:43 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8NKJKDD4-WAi; Wed, 22 Feb 2017 00:14:41 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 32D6DFF4F5; Wed, 22 Feb 2017 00:14:41 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Feb 2017 00:14:32 +0100 Message-Id: <20170221231432.15759-1-cus@passwd.hu> X-Mailer: git-send-email 2.10.2 In-Reply-To: References: Subject: [FFmpeg-devel] [PATCH] avcodec/wrapped_avframe: allocate a buffer with padding X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This ensures that the wrapped avframe will not get reallocated later, which would invalidate internal references such as extended data. Signed-off-by: Marton Balint --- libavcodec/wrapped_avframe.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libavcodec/wrapped_avframe.c b/libavcodec/wrapped_avframe.c index 13c8d8a..1436032 100644 --- a/libavcodec/wrapped_avframe.c +++ b/libavcodec/wrapped_avframe.c @@ -43,19 +43,31 @@ static int wrapped_avframe_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet) { AVFrame *wrapped = av_frame_clone(frame); + uint8_t *data; + int size = sizeof(*wrapped) + AV_INPUT_BUFFER_PADDING_SIZE; if (!wrapped) return AVERROR(ENOMEM); - pkt->buf = av_buffer_create((uint8_t *)wrapped, sizeof(*wrapped), + data = av_mallocz(size); + if (!data) { + av_frame_free(&wrapped); + return AVERROR(ENOMEM); + } + + pkt->buf = av_buffer_create(data, size, wrapped_avframe_release_buffer, NULL, AV_BUFFER_FLAG_READONLY); if (!pkt->buf) { av_frame_free(&wrapped); + av_freep(&data); return AVERROR(ENOMEM); } - pkt->data = (uint8_t *)wrapped; + av_frame_move_ref((AVFrame*)data, wrapped); + av_frame_free(&wrapped); + + pkt->data = data; pkt->size = sizeof(*wrapped); pkt->flags |= AV_PKT_FLAG_KEY;