From patchwork Fri Mar 27 02:25:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18419 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 01F8744B47E for ; Fri, 27 Mar 2020 04:25:32 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D9AAA68B849; Fri, 27 Mar 2020 04:25:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0C58868B76C for ; Fri, 27 Mar 2020 04:25:26 +0200 (EET) Received: by mail-wr1-f65.google.com with SMTP id 31so9669610wrs.3 for ; Thu, 26 Mar 2020 19:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LgAF9LAUiwBfTByZU0vqiGtPVQ6hRyjmO+zvUdnMMc4=; b=t5Uk+AY/si5Zp819HxphjrGsn6lewg9qUztKQAe3Hn7w2W9abl458J63NxqM0iqel8 GwV2rdL9+AStgYWF8tNZMFTemi0I69kx2coqhorj8fVmwNctqlmH2VZ5aRE66in8y/vX gRNRiHDsKu/PtMisIwzGJCu85hTJC4lXsuMlaFLKy9aql5VhWMjAswSvJJQm1V4gyEfK AFaMhcrfr2z3oax9Pkr5BgJ+/FOXfDmEC6offGwQjJxEeTXhCYyRVcVENnq69U+T2HCu x+7Vom2r1ho0KlEfau/vwiOvyBCCXx6jJLAQ6l2Q0gFLdmXOZv943Y9gt3rmcQhLumhn 2rag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LgAF9LAUiwBfTByZU0vqiGtPVQ6hRyjmO+zvUdnMMc4=; b=jFwwfog5314o/34+LoxrHcRCjrUPqdOOYsxhwAbTMBC1iRGItFRDf2DTQHjyC/Z8VM XhPVvDk4jTyTHxpoQQkgNyRNm+BOvRvj2NDhR6+z0UC0wQNmbqD6YWatDZPEXbZ+Q6Ec GcOxsqM7NROMaf+wr+BYbk/l2VfxJhY/TfJ40ibshHqawn8Rt3Wpc+/Wog8b/vtgNJNh G8lcGXH7qxapDv7v1D4Yb7eRaO1EhiDICuIf55Owgw5w65qeYOSsBorwNPQ+mlP/UEXz 6yldtGUIzQC1t66KtQ+N9P64SukyVP82SC9IS0wWBXvVG2vRxDoToWT+9Yo0o1C8affl wk3Q== X-Gm-Message-State: ANhLgQ1y5ES2nCIl9OT1h5YYCZ3E+rDySs66LkTiEXusaEdX+p/WsU0x RDbgZy0q0IeES5F2VdU/GDMhmjJ/ X-Google-Smtp-Source: ADFU+vsYtM3kYtwoVQ9u+Zjs/At5nX8CZEVIaGlL+EQqD2KQwKRZ8uvgRHBYUdOwFa7hb6myQoGesg== X-Received: by 2002:a5d:55cb:: with SMTP id i11mr12212222wrw.305.1585275925158; Thu, 26 Mar 2020 19:25:25 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id r15sm6542773wra.19.2020.03.26.19.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 19:25:24 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Mar 2020 03:25:13 +0100 Message-Id: <20200327022514.27554-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <158521659210.17802.7969245110754925761@lain.red.khirnov.net> References: <158521659210.17802.7969245110754925761@lain.red.khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/2] avcodec/avpacket: Always treat dst in av_packet_ref as uninitialized 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- libavcodec/avcodec.h | 2 +- libavcodec/avpacket.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 78c483c25c..f918d20a61 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -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. diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index b5667659fd..132567bc2d 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -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;