From patchwork Mon Feb 15 14:25:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 25634 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 0C41844B4E1 for ; Mon, 15 Feb 2021 16:53:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E3DCF6809CD; Mon, 15 Feb 2021 16:53:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 15AEC68052A for ; Mon, 15 Feb 2021 16:53:08 +0200 (EET) Received: by mail-lf1-f45.google.com with SMTP id h26so10676938lfm.1 for ; Mon, 15 Feb 2021 06:53:08 -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:reply-to:mime-version :content-transfer-encoding; bh=LpAXEE5+kbAYRyT6m91Bm/99qFfBdz1RAtbHRTUuVr4=; b=XXW7Z69J2Bx7vjDm+sfDNf/o3MeUf5LTQa/pagkjZJorzGK6F7HX1em80YP6FnpZkE 2GWmb3nGXuQLI9+cZs4/JEb6B/3pdvXjybAvSD1kErhDSiG92UfdBTHSO/tzazL5jPaU palvt2ewFVLFS2g/ANjke/vhPOXIkG6tV+uV8s7BlElIv78tAg0zOW6Ybz3h+4+xFooI /s4A52bPhViv4z80leBuieuNhFez4+a/fO3U8ZH0opZ1RtDdyxC0j5XQfHncHbzJqmhL eozJCcEDFW1ycR/r6fPviTMfGxHeYbEMQzgo3MC9h89wSRGKnxHb/ot1zHfdSifrEupu Q6Uw== 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:reply-to :mime-version:content-transfer-encoding; bh=LpAXEE5+kbAYRyT6m91Bm/99qFfBdz1RAtbHRTUuVr4=; b=Hk+5G9TTa9hWxZzh3vW0J8NX+2nm3J1CDnMDg57wyEKSFAmGXN9c9JkkZOTP/uzsF2 6oMdFa4LTCzCGSbl6R9sWlzhqBTN2s21RQa1FkVpGVSoIpP9GDn4Cg/gyYoRwX80hO+5 omi3k8Xvnlzd95uPZqg5wKw1K6NmrAUE0th6g08RJyX31prKDX+GKsdSJNdWR/wdL6di zBXoroIicqdGpE7RlRe69pPQNNzpy0CJlMgGdKIy/AptlhVCc895A5lkr/ueRPEAkb/m CP0sIR6qMTx8PMrcTw6YbJR+z72rhNrGN8ywcaspv4JgRS6S/qCWyI86zrKrOy7HbA0Q uvTA== X-Gm-Message-State: AOAM531p84QpolYB7dBd+oGPHuoELCyZBgCaAGLj/IpIo+saU4LdIds+ UfoI0L0fjFIyPLZ4mWJJABFFwAx0OTs= X-Google-Smtp-Source: ABdhPJw/6VshcAcRX6+/SeFe9khoQDI7VuQe+2/9aJmW63YiAYqF4d3LugDqhnyoHoRdbXuBk2HTSA== X-Received: by 2002:a17:907:2659:: with SMTP id ar25mr6113634ejc.387.1613399114282; Mon, 15 Feb 2021 06:25:14 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id y20sm9826604edc.84.2021.02.15.06.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 06:25:13 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Feb 2021 15:25:02 +0100 Message-Id: <20210215142505.514125-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avformat/mpegenc: Ensure packet queue stays valid 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" The MPEG-PS muxer uses a custom queue of custom packets. To keep track of it, it has a pointer (named predecode_packet) to the head of the queue and a pointer to where the next packet is to be added (it points to the next-pointer of the last element of the queue); furthermore, there is also a pointer that points into the queue (called premux_packet). The exact behaviour was as follows: If premux_packet was NULL when a packet is received, it is taken to mean that the old queue is empty and a new queue is started. premux_packet will point to the head of said queue and the next_packet-pointer points to its next pointer. If predecode_packet is NULL, it will also made to point to the newly allocated element. But if premux_packet is NULL and predecode_packet is not, then there will be two queues with head elements premux_packet and predecode_packet. Yet only elements reachable from predecode_packet are ever freed, so the premux_packet queue leaks. Worse yet, when the predecode_packet queue will be eventually exhausted, predecode_packet will be made to point into the other queue and when predecode_packet will be freed, the next pointer of the preceding element of the queue will still point to the element just freed. This element might very well be still reachable from premux_packet which leads to use-after-frees lateron. This happened in the tickets mentioned below. Fix this by never creating two queues in the first place by checking for predecode_packet to know whether the queue is empty. If premux_packet is NULL, then it is set to the newly allocated element of the queue. Fixes tickets #6887, #8188 and #8266. Signed-off-by: Andreas Rheinhardt --- Disclaimer: I don't know MPEG program streams very well; it might very well be that the mere fact that premux_packet can be NULL while predecode_packet isn't is indicative of a deeper bug. All I know is that this patch only changes behaviour in case the old behaviour was broken (i.e. led to leaks or use-after-frees). libavformat/mpegenc.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index 9bd0a555d4..810dd717ca 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -48,9 +48,9 @@ typedef struct StreamInfo { uint8_t id; int max_buffer_size; /* in bytes */ int buffer_index; - PacketDesc *predecode_packet; + PacketDesc *predecode_packet; /* start of packet queue */ + PacketDesc *last_packet; /* end of packet queue */ PacketDesc *premux_packet; - PacketDesc **next_packet; int packet_number; uint8_t lpcm_header[3]; int lpcm_align; @@ -986,6 +986,8 @@ static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr) } stream->buffer_index -= pkt_desc->size; stream->predecode_packet = pkt_desc->next; + if (!stream->predecode_packet) + stream->last_packet = NULL; av_freep(&pkt_desc); } } @@ -1177,12 +1179,16 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) av_log(ctx, AV_LOG_TRACE, "dts:%f pts:%f flags:%d stream:%d nopts:%d\n", dts / 90000.0, pts / 90000.0, pkt->flags, pkt->stream_index, pts != AV_NOPTS_VALUE); - if (!stream->premux_packet) - stream->next_packet = &stream->premux_packet; - *stream->next_packet = pkt_desc = av_mallocz(sizeof(PacketDesc)); if (!pkt_desc) return AVERROR(ENOMEM); + if (!stream->predecode_packet) { + stream->predecode_packet = pkt_desc; + } else + stream->last_packet->next = pkt_desc; + stream->last_packet = pkt_desc; + if (!stream->premux_packet) + stream->premux_packet = pkt_desc; pkt_desc->pts = pts; pkt_desc->dts = dts; @@ -1200,9 +1206,6 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) pkt_desc->unwritten_size = pkt_desc->size = size; - if (!stream->predecode_packet) - stream->predecode_packet = pkt_desc; - stream->next_packet = &pkt_desc->next; if (av_fifo_realloc2(stream->fifo, av_fifo_size(stream->fifo) + size) < 0) return -1; From patchwork Mon Feb 15 14:54:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 25635 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 376AD44B636 for ; Mon, 15 Feb 2021 16:54:44 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 18E22687FE1; Mon, 15 Feb 2021 16:54:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C6149680466 for ; Mon, 15 Feb 2021 16:54:37 +0200 (EET) Received: by mail-wm1-f42.google.com with SMTP id m1so9608798wml.2 for ; Mon, 15 Feb 2021 06:54:37 -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:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=IExpure88PSjin4AJCD9HasgDDAgeDUrbqWczSlqrd4=; b=hg8/Z6y3IWYv2amBVfkD9ItlEuA9ryENz4InqI2AlV0ITReU3PIueRqo6wlMdtu3fI LYeOI6T+U+gw+wjc5zafEXypQcZdY3bB7ZDrxpxdAuPUuhd4yMCDFGz1wH27VnpG0vDt NDmH5N4d/7W73CCD+ffqrQOIkQCKIjtiB/Sg2hHf4t6PKQCt3S1UOxSeXyIVmsC5xdu2 IlQ1dT20wBni9OP3ROqqUQZ56+2HKVTfeKqRw6eXUEkUcYAkTWmbboW1voPJxVQYV+Fo oDzWNrpLpM6tUxaWKlBwOPQxL3E7AwKjaOTgXwvIKBzXjhbCYgsoZOOkjJf3nIBRL7rO ewhQ== 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:reply-to:mime-version:content-transfer-encoding; bh=IExpure88PSjin4AJCD9HasgDDAgeDUrbqWczSlqrd4=; b=RW0paGghMuxSq7qOVWIDCkys2qnUMjfQCJjt9Rh1t8l0jL02N5klmuhwKKWQGBwWuU h7Iu5xRTb4QqSOYFvjPKP+QKgFeaXG3OP2mJov6lccAHPuwh8LX46CSEurkxVZBDFEoW ow4lJ65TFprNSlHPHn0J+21kTbo9ah2YUg5pddyYq/+zQ/aCyFk/4De/gc8p3G+Ib2FI wTGFNFkmECd+ASbvwaIye1rLAlAwCKxWUwg4BQ9xGUNED6YqHFjKkrZYHwKdjrfiUnZi aIVPw8jX+rzfjbivbkZ/QVA7gi8YOOryehazLJtaJejxtLTlxMSF4xz9QdQNxjGuW7AV nXRg== X-Gm-Message-State: AOAM532fX/tFS17cwr8Cwfhdd0vxBdQpkNdDgOYgic+jJk/VXTRtRcLb 2HE2XvJ2G/7ksJUB7/iKLiFykjpK/gk= X-Google-Smtp-Source: ABdhPJxyMkG+80fZWEIf6jVf3nLM8B4pJATdRAZ7W/OXcG7bzH72LuqSIi1Nx1UyFEyNU3l6erLjRw== X-Received: by 2002:a1c:730f:: with SMTP id d15mr14506894wmb.135.1613400877182; Mon, 15 Feb 2021 06:54:37 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id t6sm14835694wrn.96.2021.02.15.06.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 06:54:36 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Feb 2021 15:54:21 +0100 Message-Id: <20210215145423.591629-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210215142505.514125-1-andreas.rheinhardt@gmail.com> References: <20210215142505.514125-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] avformat/mpegenc: Fix leak in case trailer is never written 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" Signed-off-by: Andreas Rheinhardt --- libavformat/mpegenc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index 810dd717ca..1204e57f04 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -1262,6 +1262,11 @@ static void mpeg_mux_deinit(AVFormatContext *ctx) StreamInfo *stream = ctx->streams[i]->priv_data; if (!stream) continue; + for (PacketDesc *pkt = stream->predecode_packet; pkt; ) { + PacketDesc *tmp = pkt->next; + av_free(pkt); + pkt = tmp; + } av_fifo_freep(&stream->fifo); } } From patchwork Mon Feb 15 14:54:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 25636 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 4192B44B636 for ; Mon, 15 Feb 2021 16:55:01 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 27295680466; Mon, 15 Feb 2021 16:55:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 03EDD68065D for ; Mon, 15 Feb 2021 16:54:54 +0200 (EET) Received: by mail-wm1-f45.google.com with SMTP id l17so6479351wmq.2 for ; Mon, 15 Feb 2021 06:54:53 -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:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=YQHAwG5w+iohSxZ3Ofp71x78LJ6K6r0mGIbwynlbgLs=; b=uJZ2wA1NWtZA1SLC2O47gO/Yldq6kMO8uReYO9SwfDQ8ufLShZTXrQLWtmLXAqO77J sei69uXZZWmeLXphX1A2ypgjwzjNq9/EyGZbNwZIYKJkVrCglfBFAg5bivPEr6eDXQeo ATCWO1ne2FP0ywZtn7qnIL/sbZJ4JHCEWkOk4nLh/Y7fIbDQlyOJ37qG7aYMbo7YZcHi rIoML2EU/yLOwh6muxLcUdCkA3RWkzHdBr2F3S/g302eD/K3mKCKQgabChItwyA7Hx5g wNKOfO0L9fOLpo06BemWZk5BbHWM2RTCeNSUlHQRhQxe3X3uSb3E+yG1iSeU9aTdzpla v9fQ== 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:reply-to:mime-version:content-transfer-encoding; bh=YQHAwG5w+iohSxZ3Ofp71x78LJ6K6r0mGIbwynlbgLs=; b=CJ+NrcceDpQltAdePPypSYO2lXE//onPKQ5dhuX7eBe6hreV0+SxA3TDq4I0/uCgMA yRiCBIq7Te1Dt5w3NFLKeIoNY4ul6lOnlkCAu1/BfnMWx258QAlKhDKl+QdkR8mm+0Rc VnOho6kE2m/q4bTOOnWa5iMOdtfGUxHcEGGTOQfHvmX1KGCo5Mp5PTbZYKuHwUXNKCZt 4uGQyLMJV9eNfF2Lue58garG7XwZvwYfrYc3JnKZ9IFOORBOFZl1axDqN4SzmDUFS+fc K4Qplt+2omqR4KEgOj16UnuCg8CXLYYNRrJ8HHPrADnluVq+NL07OK0fD0PJHqrPZlNO hZZw== X-Gm-Message-State: AOAM533la7IfZNXN2alKzJ1x++zJe7h/y2F3PZ6Wxc6JrqZjXnBhH9fn IVttYNAP08FUXfHMDM3VUH8xWHsAbRQ= X-Google-Smtp-Source: ABdhPJwjyNL1qkJd3OKRfrQgzkDXUGWsZHmIrba2Gdi5M4uQtdfgOIr1xTfmvgKRZ7EFkc6mEd1R8w== X-Received: by 2002:a05:600c:3502:: with SMTP id h2mr2136535wmq.107.1613400893346; Mon, 15 Feb 2021 06:54:53 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id t6sm14835694wrn.96.2021.02.15.06.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 06:54:53 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Feb 2021 15:54:22 +0100 Message-Id: <20210215145423.591629-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210215145423.591629-1-andreas.rheinhardt@gmail.com> References: <20210215142505.514125-1-andreas.rheinhardt@gmail.com> <20210215145423.591629-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] avformat/mpegenc: Avoid adding invalid packet to queue 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" Do this by moving the check before the allocation. Signed-off-by: Andreas Rheinhardt --- libavformat/mpegenc.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index 1204e57f04..14b904b152 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -1179,18 +1179,6 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) av_log(ctx, AV_LOG_TRACE, "dts:%f pts:%f flags:%d stream:%d nopts:%d\n", dts / 90000.0, pts / 90000.0, pkt->flags, pkt->stream_index, pts != AV_NOPTS_VALUE); - pkt_desc = av_mallocz(sizeof(PacketDesc)); - if (!pkt_desc) - return AVERROR(ENOMEM); - if (!stream->predecode_packet) { - stream->predecode_packet = pkt_desc; - } else - stream->last_packet->next = pkt_desc; - stream->last_packet = pkt_desc; - if (!stream->premux_packet) - stream->premux_packet = pkt_desc; - pkt_desc->pts = pts; - pkt_desc->dts = dts; if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) { if (size < 3) { @@ -1204,6 +1192,18 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) size -= 3; } + pkt_desc = av_mallocz(sizeof(PacketDesc)); + if (!pkt_desc) + return AVERROR(ENOMEM); + if (!stream->predecode_packet) { + stream->predecode_packet = pkt_desc; + } else + stream->last_packet->next = pkt_desc; + stream->last_packet = pkt_desc; + if (!stream->premux_packet) + stream->premux_packet = pkt_desc; + pkt_desc->pts = pts; + pkt_desc->dts = dts; pkt_desc->unwritten_size = pkt_desc->size = size; From patchwork Mon Feb 15 14:54:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 25638 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 3CB8A44B819 for ; Mon, 15 Feb 2021 16:55:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 259FB68811F; Mon, 15 Feb 2021 16:55:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3535768066B for ; Mon, 15 Feb 2021 16:55:04 +0200 (EET) Received: by mail-wm1-f49.google.com with SMTP id j11so6455061wmi.3 for ; Mon, 15 Feb 2021 06:55:04 -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:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=FMssZwgUT7w2b8xza12C/VrJDRV4uiZPzqhvCV6s2EA=; b=b1zRPyPtmniteqJqDqavzthJ23M4czUn8n3dYSXgQxt/uqTkEQ38JT4Z/L8nU6ZeA5 qwAzy+6Ntakz0gIHa459bB1pTjNU4joysIZsrspxSJwhXkRhKonyu1/ck7aWZ6lg3NkN So81gPSwhSKBL+gMJ+hGSRE6qKFzQcpqI/pUyKG67wguFfxViQmuEPogILT6IfxpyqRt R3tAWKMDfQTMGfwkR8AXGdfZ7qR1CYVUBgHDBxo9Tszz8aj3Cx/AcD1pxv+5Wm2kdiDX aOgIfa0JLfJ2W7XDNHvWeOt/QNvN+HtNeJ3cuUNoHnMav1T8khsW6i9ltqFBMpe1paZR 3kLw== 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:reply-to:mime-version:content-transfer-encoding; bh=FMssZwgUT7w2b8xza12C/VrJDRV4uiZPzqhvCV6s2EA=; b=h2b5S34QGuQXxAbb2JDcwiF86FKqZOMDwOddjoRzM6yLRUUqBI8kyuF7bKed8jCxb9 sBYGbYKxwYI2HNT3riX4HbUOvqF722N9AZxQh0T2EOIu1403eBZjMBYPXcAd9y0tgkGE wlruU56WadiDu4OUCAAEclzB/EWccq/EvIO95PgkDupJ+Ng1HXvN9nFEElAQLpnsylY+ BpUTMTplAfHWcxEpOHkvIHtPXqgUs+Rq5S56T9HTwAz46alKLSfWKOOYCkkJRtsyF1hn SiM17lcR2pvIFNhcwngZIRrFMavxOw1PFMl+HVzo63vpFBdPqF3FtwQsO7ZZqi1ftwmx Faig== X-Gm-Message-State: AOAM530Dj/ym8X7Fa2BLQbBuxvPPY0IJvRJLvG8O7O4jq/bfWRYlIkNt 0CFd4xmx4VtrDTKsTuDNGbOo4+buNSk= X-Google-Smtp-Source: ABdhPJw8KrF4DhW9d7BKi8o1zuL03OOYTon04s2y6k7rgKqSZ7ne1pp/OSGG65JThYnknL8+lxXJew== X-Received: by 2002:a05:600c:4f56:: with SMTP id m22mr10748481wmq.143.1613400903535; Mon, 15 Feb 2021 06:55:03 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id t6sm14835694wrn.96.2021.02.15.06.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 06:55:03 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Feb 2021 15:54:23 +0100 Message-Id: <20210215145423.591629-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210215145423.591629-1-andreas.rheinhardt@gmail.com> References: <20210215142505.514125-1-andreas.rheinhardt@gmail.com> <20210215145423.591629-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avformat/mpegenc: Forward error code 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" Signed-off-by: Andreas Rheinhardt --- libavformat/mpegenc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index 14b904b152..d37f181eaa 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -1151,7 +1151,7 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) StreamInfo *stream = st->priv_data; int64_t pts, dts; PacketDesc *pkt_desc; - int preload; + int preload, ret; const int is_iframe = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && (pkt->flags & AV_PKT_FLAG_KEY); @@ -1207,8 +1207,9 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) pkt_desc->unwritten_size = pkt_desc->size = size; - if (av_fifo_realloc2(stream->fifo, av_fifo_size(stream->fifo) + size) < 0) - return -1; + ret = av_fifo_realloc2(stream->fifo, av_fifo_size(stream->fifo) + size); + if (ret < 0) + return ret; if (s->is_dvd) { // min VOBU length 0.4 seconds (mpucoder)