From patchwork Thu Feb 23 14:19:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 2659 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.149 with SMTP id x21csp235173vsf; Thu, 23 Feb 2017 06:19:53 -0800 (PST) X-Received: by 10.223.178.9 with SMTP id u9mr21340475wra.121.1487859593642; Thu, 23 Feb 2017 06:19:53 -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 s7si7151113wmd.57.2017.02.23.06.19.52; Thu, 23 Feb 2017 06:19:53 -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 36FD4688396; Thu, 23 Feb 2017 16:19:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe02-3.mx.upcmail.net (vie01a-dmta-pe02-3.mx.upcmail.net [62.179.121.159]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6083468837F for ; Thu, 23 Feb 2017 16:19:28 +0200 (EET) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe02.mx.upcmail.net with esmtp (Exim 4.87) (envelope-from ) id 1cguF6-0004YQ-DY for ffmpeg-devel@ffmpeg.org; Thu, 23 Feb 2017 15:19:36 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id oEKb1u00L0S5wYM01EKcMN; Thu, 23 Feb 2017 15:19:36 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 23 Feb 2017 15:19:31 +0100 Message-Id: <20170223141932.31110-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170223141932.31110-1-michael@niedermayer.cc> References: <20170223141932.31110-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 3/4] avutil/frame: Reimplement av_frame_new_side_data() without size=0 special case 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The size 0 special case causes side data to be created which is different and a special case if for any reasons size = 0 is passed Fixes: multiple runtime error: null pointer passed as argument 1, which is declared to never be null Fixes: 653/clusterfuzz-testcase-5773837415219200 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg Signed-off-by: Michael Niedermayer --- libavutil/frame.c | 55 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 2913982e91..8811dcdcfe 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -26,6 +26,11 @@ #include "mem.h" #include "samplefmt.h" + +static AVFrameSideData *frame_new_side_data(AVFrame *frame, + enum AVFrameSideDataType type, + AVBufferRef *buf); + MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp) MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration) MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_pos) @@ -344,20 +349,11 @@ FF_ENABLE_DEPRECATION_WARNINGS } memcpy(sd_dst->data, sd_src->data, sd_src->size); } else { - sd_dst = av_frame_new_side_data(dst, sd_src->type, 0); + sd_dst = frame_new_side_data(dst, sd_src->type, av_buffer_ref(sd_src->buf)); if (!sd_dst) { wipe_side_data(dst); return AVERROR(ENOMEM); } - if (sd_src->buf) { - sd_dst->buf = av_buffer_ref(sd_src->buf); - if (!sd_dst->buf) { - wipe_side_data(dst); - return AVERROR(ENOMEM); - } - sd_dst->data = sd_dst->buf->data; - sd_dst->size = sd_dst->buf->size; - } } av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0); } @@ -633,40 +629,47 @@ AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane) return NULL; } -AVFrameSideData *av_frame_new_side_data(AVFrame *frame, - enum AVFrameSideDataType type, - int size) +static AVFrameSideData *frame_new_side_data(AVFrame *frame, + enum AVFrameSideDataType type, + AVBufferRef *buf) { AVFrameSideData *ret, **tmp; - if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1) + if (!buf) return NULL; + if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1) + goto fail; + tmp = av_realloc(frame->side_data, (frame->nb_side_data + 1) * sizeof(*frame->side_data)); if (!tmp) - return NULL; + goto fail; frame->side_data = tmp; ret = av_mallocz(sizeof(*ret)); if (!ret) - return NULL; - - if (size > 0) { - ret->buf = av_buffer_alloc(size); - if (!ret->buf) { - av_freep(&ret); - return NULL; - } + goto fail; - ret->data = ret->buf->data; - ret->size = size; - } + ret->buf = buf; + ret->data = ret->buf->data; + ret->size = buf->size; ret->type = type; frame->side_data[frame->nb_side_data++] = ret; return ret; +fail: + av_buffer_unref(&buf); + return NULL; +} + +AVFrameSideData *av_frame_new_side_data(AVFrame *frame, + enum AVFrameSideDataType type, + int size) +{ + + return frame_new_side_data(frame, type, av_buffer_alloc(size)); } AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,