From patchwork Wed Feb 12 15:02:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17760 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 BEE5E44B397 for ; Wed, 12 Feb 2020 17:29:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9565668A76A; Wed, 12 Feb 2020 17:29:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1910C689F6B for ; Wed, 12 Feb 2020 17:29:25 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id w12so2892848wrt.2 for ; Wed, 12 Feb 2020 07:29:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wU4giydALLhOuCdCJriU+eNMkNYw3UiKQPMg3kCFQgA=; b=jvaW/b6AQO1NJwoCtRLlYN82Q9RNY0FC9CcFIDqZfw9J6nAyUESBDrzQFMlPdmb4gX aUIj2+Mthn+fLsk0HUFJerS/BQ+/de+PBU3aIR6J686oAxKyousPw1+NDmrb0mbXaIpN OF/O91imkaqK3c4bdZ/jZPvpRAtSYKx3tkrZ9rwfJ6aSklOWxfrVHlwTL64AVSzrTHjX Afl7Bi4HwyCkxwlJlAz1qV38babvinMojLbEGr9HR3xWZsnI4/P+cYQtVaQhtGzjzXJ3 iST1ncWGyFzZ54mF5dasF00+91G5NTpKoElnOZH+OBXYMgdATAg1/ai7wUUhkBp28aNS T4Bw== 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:mime-version :content-transfer-encoding; bh=wU4giydALLhOuCdCJriU+eNMkNYw3UiKQPMg3kCFQgA=; b=f7611cZLq1PzsRiGazVPa2abfZKZzGGzl/PtxKDH/9P2OwdWJLHcbj7IWNLrDT79pV IErKsMgmdW+39JP9ysbqQXQOSrBvtywyTHT+YaNRlq2b/Fz60v9yEe5oWFP/vJPUlwbO D78QoWOleYS15ff0rrMjuSnCpKQ7zPuJlsCYtNYkeq5za0ye06p2gH3hcGLXB5WC4ao8 IRGyjEySi+QJtnbPsI/xYUIQJ2EQ9sybbAIfG2RALFozi61uWhrA9sccxxA7G6tNTm5M as1Babisn5k6VZHQOqwASfG9wHYwR/JPlTjbtozPYgP7GpJckemg8N+9cII2PJE1jx4X LALw== X-Gm-Message-State: APjAAAWuyb/AdqjxoCAFFuVZR2tBQ5LREp1M1F+6TR3ZB5b2PSb5y1Cd Dri5+1OwgxW+aSBMBdP1nQtQqHAC X-Google-Smtp-Source: APXvYqxzJFAzwD3qFst493YlWCYAK0j3QfliBI48GF4Na1mKhcNlCOr67B4+Kc/ch0h3vhicIWVJpw== X-Received: by 2002:a5d:56ca:: with SMTP id m10mr16279649wrw.313.1581519752073; Wed, 12 Feb 2020 07:02:32 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1ab4b.dynamic.kabel-deutschland.de. [188.193.171.75]) by smtp.gmail.com with ESMTPSA id g25sm10403770wmh.3.2020.02.12.07.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Feb 2020 07:02:31 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Feb 2020 16:02:21 +0100 Message-Id: <20200212150223.28790-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] 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 dc5807324f..982a545dc6 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -4600,7 +4600,7 @@ void av_packet_free_side_data(AVPacket *pkt); * * @see av_packet_unref * - * @param dst Destination packet + * @param dst Destination packet. Will be treated as initially uninitialized. * @param src Source packet * * @return 0 on success, a negative AVERROR on error. diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 74845efcd2..0d9ddeee07 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -614,6 +614,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;