From patchwork Thu Jan 5 11:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39885 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp297526pzb; Thu, 5 Jan 2023 03:08:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXuwdxoa4ZckT76wPbMnLDBgVHiUErRi2dbuG1KUbJMvnVfW+9rune+KnrzDIQ0n0GxCMQhX X-Received: by 2002:a17:907:a0cc:b0:78d:f455:b5fa with SMTP id hw12-20020a170907a0cc00b0078df455b5famr43435415ejc.58.1672916916526; Thu, 05 Jan 2023 03:08:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672916916; cv=none; d=google.com; s=arc-20160816; b=mKvjn0BbJlG4Gp4yu9ZRyda+IbFxn+mwQmIFHBvTo1RB3vqYuWBxkJgxK6L3uGXj+r HL2JBK/hmdvL5VlDB9UGKOZ+keRIafspS3sWNmNBkmZIutpOkRnqAmzyPIltBguX/hw9 l5vFDjgFTXPDq2AowLHj8JIpZHGpXC06dtYDPXAq1LrCeC5+e9RBnsKqLQ6PmxTX0IHP /Cu+l7u2uOtJcpKNbT+8Tib+IXs20KHa1YQT/Tk/YM8GXiVcBJLNG/2meYdLWlqK2vI+ nnpVFR6jbtNmESFxxJNJ2oRerx815Dty6tED0/lUyZPnF236rq9e7zgiB/RQ0NtKJyTn oeog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=L8JjsVallWsGNYgypBqQAC8g44hgdIglHh90fUPIILk=; b=zpVk52jv09mLjB6w4yKuvF6512nKJxMc02JkeoBIgmu3pPlhHyWpvU30oXwfMxSM79 mlllrWfO8O3oXEYyfWqdigy4AJr7rWIeICn28qcUj+YR99NnBo/+x6Dwdkz9ChKEElgn lFwIS9glziiInvS9VvzqPjYt+fBu4o5K7UhCqogpwUJhxgsannZw8lcj4nt7afljEXvl hJo32R28Dni7uLLOs6boYhN6dxF9PKKW0Dv9VtZUgT6aKoTVaENX3bhVe1tVieb+h7VV Jfqx1j99LPXkMO8PmbyFeEccqD02fUPeMvdfBArDBvZ6tUuhseoRvTvvzrYS2uKQ7D5o 3zPA== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ht11-20020a170907608b00b007c0e15d36b8si34304760ejc.732.2023.01.05.03.08.35; Thu, 05 Jan 2023 03:08:36 -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 ADD9F68BCC0; Thu, 5 Jan 2023 13:08:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 18BE168BC58 for ; Thu, 5 Jan 2023 13:08:01 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D0C792404F7 for ; Thu, 5 Jan 2023 12:08:00 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 4LT1VN1eYqO1 for ; Thu, 5 Jan 2023 12:07:58 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id C46362400F5 for ; Thu, 5 Jan 2023 12:07:58 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 870FE3A02AF for ; Thu, 5 Jan 2023 12:07:58 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Jan 2023 12:07:53 +0100 Message-Id: <20230105110756.473-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] lavc/ac3dec: fail when the sample rate is unset X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: epGKD3SKJTIl --- libavcodec/ac3dec.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index 1f2949dcfd..0b120e6140 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -1716,6 +1716,11 @@ skip: avctx->bit_rate = s->bit_rate + s->prev_bit_rate; } + if (!avctx->sample_rate) { + av_log(avctx, AV_LOG_ERROR, "Could not determine the sample rate\n"); + return AVERROR_INVALIDDATA; + } + for (ch = 0; ch < EAC3_MAX_CHANNELS; ch++) extended_channel_map[ch] = ch; From patchwork Thu Jan 5 11:07:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39882 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp297253pzb; Thu, 5 Jan 2023 03:08:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXuSXt7jLLAqZPeMxUTvfZynHJL0sQ9vGs8QZityMghJ/i+gtu+Sg7TcFMF0taGM04bf1Wa6 X-Received: by 2002:a05:6402:ea0:b0:46f:68d0:76 with SMTP id h32-20020a0564020ea000b0046f68d00076mr35652674eda.34.1672916892751; Thu, 05 Jan 2023 03:08:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672916892; cv=none; d=google.com; s=arc-20160816; b=d1ZGYAUtX0hpE0u+54abiZLc81zeYQI137sWSqGUhOwWmH21VtyTLuUjVJsph01WoK z0ht29iHdPYBsIgePOnJ5Jkcp78Pm6jPoW/kv7S3x41a33I2g2rsxvA9IHwsuYM1Ws9b CjRiyXs4gLbWYJdmZjlYhKJsffDA0/PDFTZyIJK9YBoSiIhDJdiSGv2A5FxbxiRjjyI5 9ZPN3YNyM8+J53GD5INSC2iiO0V1nW4FFqTJZVR+d2PnD/F29md8rDhT4aUWmY4oaS8b resMKW1NCfxL500okrsaXPsofw/8PxwtH1fGIkuHiBKWNSpp9P+531QNvU7MX7RWK4pI jv/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=jAw1TXhuHlTWlJjGQd2TGlVDyRbtt0ESkKUBSSWI9Fc=; b=QGtV2Rfa8VMo9shhJC308Y1teeJLLiaZ7fz/sw+OWXHeWd78qJBEVBaGcWa4zWisaN qHFSi7beCS8Y/QHb8oz0dqNKMbuvmnyjMvHe9ofmAtYkJW30u0PHb2WnRucHFQHWe4iN /smbhJ+wqogHHSbpHQdDbaUXtbvE3kEfcruo3ZnVMXMlRe+S5a692gC90+1PBa3I2n0a 2v9MkIchE/DP7oZmLrXR6CTdTRmdfaEpEmSJBXkQIet8uVe64IrhTxfcfXQ5k5eCCQwN Tugu4QzBY8N/NryzzNv3E5l14udI70R8CHd1G8hpCxq1yYqnMZ5yVfmbWZHQcIUkSmzV V/8g== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ds15-20020a0564021ccf00b00492c006b79asi1357844edb.434.2023.01.05.03.08.10; Thu, 05 Jan 2023 03:08:12 -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 937B568BCBB; Thu, 5 Jan 2023 13:08:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8C21C68BC58 for ; Thu, 5 Jan 2023 13:07:59 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4C0A9240591 for ; Thu, 5 Jan 2023 12:07:59 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id A-7G2BTn_Gsp for ; Thu, 5 Jan 2023 12:07:58 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id C8EB3240499 for ; Thu, 5 Jan 2023 12:07:58 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 92C543A0344 for ; Thu, 5 Jan 2023 12:07:58 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Jan 2023 12:07:54 +0100 Message-Id: <20230105110756.473-2-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230105110756.473-1-anton@khirnov.net> References: <20230105110756.473-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] lavc/qsvdec: check ff_decode_frame_props() return value X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: S0UoZGY54+CD --- libavcodec/qsvdec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index 92bfea196e..6bc85116ad 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -128,7 +128,9 @@ static int qsv_get_continuous_buffer(AVCodecContext *avctx, AVFrame *frame, { int ret = 0; - ff_decode_frame_props(avctx, frame); + ret = ff_decode_frame_props(avctx, frame); + if (ret < 0) + return ret; frame->width = avctx->width; frame->height = avctx->height; From patchwork Thu Jan 5 11:07:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39884 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp297431pzb; Thu, 5 Jan 2023 03:08:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXuVHXjJ94Qzn7Khih7R9wiIVzNkuxz9aAt4j52DHtHJVnUqH5/pOyQHI+jI62hB4W2bUWTQ X-Received: by 2002:a05:6402:f04:b0:46d:ca42:2e59 with SMTP id i4-20020a0564020f0400b0046dca422e59mr48671644eda.11.1672916908210; Thu, 05 Jan 2023 03:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672916908; cv=none; d=google.com; s=arc-20160816; b=fjCuGlyaO70H24Vh9dNWjLSrA62nN6nPDK7+xJ0wvPQMA8gJDI2pjQTlVteoaM5EHN 5YAEnI8D+kgfEAJ0/joZdeVRpYhfd3tLTXJMnxhIuF9DngcNgeTX4/n7JWIswKVUUJ7/ XG1NxbvOyVfpvdyjYsuMoR7VOrAmCTCxdoB8EKfcW+IVuKFzR4qvnwf2WdUUU+jhIhbp gEsTsSE+egUNYf0bzaRHRLswnYyS12NLCknuGtpgi19CUTRyC7vP1cuaMmNsvsRw9Y9N ZHL2am7r2+tvdDDXlQaF/RFVIaI/nIeVODoFL1ENkH0OA7lvfkPZaYp0Q5cQvmqZRxZi uVdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=kD8HDPz4Txc+NxsQzonky1QtmrZEW+E/1a41BXKdn9I=; b=Rz+QmLuzyayWCPpfiYzyJJL9vwTbwRBGd99PVmdWODlYR0f/71HKZ+oLf0iA4bkPx9 e16srD7IJJtFl6zwEQ9fQ0dG0GMZT4MG9rRb7Yum53vDvJowe/dAfGjR1iX/1m0y57nW WPldoxJvWLHwLL5U4fyDrz8O4IUUVjH0EY7y9GdbH5pjegVMoI9bBBjc023nNEtwHWS5 sO2OrJ18p1N1oBtv3j8ekfFWBJCq3AQPw7tniZoEV/O1ceX1GGQB5aumRexVKNnI0ZFS eelZAYNRP7uRIQjwIEnd/8Ey+QLlQslPvZ4xrOI1gjoiW1HXsS9s6HSozftfgy4ZS89m C0NQ== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id wu8-20020a170906eec800b007a1d4f0e7fcsi16635540ejb.655.2023.01.05.03.08.27; Thu, 05 Jan 2023 03:08:28 -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 A01B368BD12; Thu, 5 Jan 2023 13:08:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A0D8E68B71D for ; Thu, 5 Jan 2023 13:08:00 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6095E2404F8 for ; Thu, 5 Jan 2023 12:08:00 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 0QUZKDRicB-H for ; Thu, 5 Jan 2023 12:07:59 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id D25592404F7 for ; Thu, 5 Jan 2023 12:07:58 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9E4153A034A for ; Thu, 5 Jan 2023 12:07:58 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Jan 2023 12:07:55 +0100 Message-Id: <20230105110756.473-3-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230105110756.473-1-anton@khirnov.net> References: <20230105110756.473-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] lavc/decode: deduplicate cleanup in ff_decode_receive_frame() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: V8AeXEaaCzzE --- libavcodec/decode.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 3e5be501b9..56ba06d5d5 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -685,10 +685,8 @@ int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame) if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { ret = apply_cropping(avctx, frame); - if (ret < 0) { - av_frame_unref(frame); - return ret; - } + if (ret < 0) + goto fail; } avctx->frame_number++; @@ -706,10 +704,8 @@ int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame) avci->initial_sample_rate = frame->sample_rate ? frame->sample_rate : avctx->sample_rate; ret = av_channel_layout_copy(&avci->initial_ch_layout, &frame->ch_layout); - if (ret < 0) { - av_frame_unref(frame); - return ret; - } + if (ret < 0) + goto fail; break; } } @@ -735,12 +731,15 @@ int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame) " drop count: %d \n", avctx->frame_number, frame->pts, avci->changed_frames_dropped); - av_frame_unref(frame); - return AVERROR_INPUT_CHANGED; + ret = AVERROR_INPUT_CHANGED; + goto fail; } } } return 0; +fail: + av_frame_unref(frame); + return ret; } static void get_subtitle_defaults(AVSubtitle *sub) From patchwork Thu Jan 5 11:07:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39883 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp297390pzb; Thu, 5 Jan 2023 03:08:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXtm7gUIpbYNo7AyWeHQzHksUWwQKexk3oLrJAOj8ugYjFC/a2F9/0k45rmrusA8BGNhLGau X-Received: by 2002:a05:6402:5145:b0:462:7b85:33aa with SMTP id n5-20020a056402514500b004627b8533aamr42966825edd.2.1672916905473; Thu, 05 Jan 2023 03:08:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672916905; cv=none; d=google.com; s=arc-20160816; b=XRfnwg1pNXIhyd5JEw849i7hJUK5A1BpvM43OSzHFmHnF2NQ1RqWDdnxeVVA/whX0m cywWhQYy+EyBMZ4gB9DVvX/k+Zglsu61t9NgDG5rMpxrvt/rJTYwl/U4Si1MCUwTulVO i75LxLDngl/noXnLvW4bK7GkWYqI3fJQL38j5XyrOv8z53W3nx7g7vG4Zjii3Go7cLup PA+rD/8yq3x9HAn4bA6eGInqs80JW5mULV2413UMyfqfPrnx9bYNkqrBUOf3J+T0j8bm 0+BBG3wDzuNbMD9zKt1pS9pzheXmH9Zaml7qL1Yl+tsstFbf/oMf0491amjtgLt4yJ4r n1nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=C2QH21rYFyji23/usoVPGCedcTIerdvMk48QKh7/V64=; b=WfqrzFqHQFLUxqAfDVpNp+cs2j+08VQABJxfccuqLnCXdOx7Md+leowFD8TWCpWW8z C5zSDyYfOLRdtyAqB8wlSgNQA22Q9jIkTFMIWAVjoUKxn0uOBpwQJlnFd3Iic+rOQOMJ s59ReY281adSxLis59df9Olk9TIeXssHp1fouQEDTFVIpdyiLihu8cZ3RqAhlM+gyqFh T7lo0uZuN+9WXkbD9KFX+9qAbuaSYkFZzyhc499knncHhUM8v8Ssx1GkCdBiGBH0NLzo +bm8uijsYoi8z0Yg/z4qJaWYbddl0V9iwPgh+bkwp3ckpy3Gbh9/LLajAsGt9wWnBzEH sWVw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f16-20020a056402355000b004853521ef69si30333649edd.258.2023.01.05.03.08.18; Thu, 05 Jan 2023 03:08:25 -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 96CDE68BCEB; Thu, 5 Jan 2023 13:08:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A53D68BC58 for ; Thu, 5 Jan 2023 13:08:00 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D5B52240499 for ; Thu, 5 Jan 2023 12:07:59 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id EZnbS5MMldSn for ; Thu, 5 Jan 2023 12:07:59 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id D8ABF2404F8 for ; Thu, 5 Jan 2023 12:07:58 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A91693A034C for ; Thu, 5 Jan 2023 12:07:58 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Jan 2023 12:07:56 +0100 Message-Id: <20230105110756.473-4-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230105110756.473-1-anton@khirnov.net> References: <20230105110756.473-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] lavc/decode: validate frames output by decoders X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AWy7heRooGu+ Make sure no frames with invalid parameters will be seen by the caller. --- libavcodec/decode.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 56ba06d5d5..0abc88737b 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -667,6 +667,33 @@ static int apply_cropping(AVCodecContext *avctx, AVFrame *frame) AV_FRAME_CROP_UNALIGNED : 0); } +// make sure frames returned to the caller are valid +static int frame_validate(AVCodecContext *avctx, AVFrame *frame) +{ + if (!frame->buf[0] || frame->format < 0) + goto fail; + + switch (avctx->codec_type) { + case AVMEDIA_TYPE_VIDEO: + if (frame->width <= 0 || frame->height <= 0) + goto fail; + break; + case AVMEDIA_TYPE_AUDIO: + if (!av_channel_layout_check(&frame->ch_layout) || + frame->sample_rate <= 0) + goto fail; + + break; + default: av_assert0(0); + } + + return 0; +fail: + av_log(avctx, AV_LOG_ERROR, "An invalid frame was output by a decoder. " + "This is a bug, please report it.\n"); + return AVERROR_BUG; +} + int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame) { AVCodecInternal *avci = avctx->internal; @@ -683,6 +710,10 @@ int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame) return ret; } + ret = frame_validate(avctx, frame); + if (ret < 0) + goto fail; + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { ret = apply_cropping(avctx, frame); if (ret < 0)