From patchwork Thu May 4 18:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41470 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp600194pzb; Thu, 4 May 2023 11:50:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5zvXqaIA9P+AEVKEoO2ANm9Z3Zkecymz5ExCj1PtIOBPJpjX6Zr5Y2ZuEXTykiUejXCvw1 X-Received: by 2002:a17:906:58d6:b0:94f:2a13:4e01 with SMTP id e22-20020a17090658d600b0094f2a134e01mr8398826ejs.74.1683226240379; Thu, 04 May 2023 11:50:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683226240; cv=none; d=google.com; s=arc-20160816; b=M1OZFsBnUEBiHiA3lL1EFL+9X1FWj0lt9ZK3i9kQ7ue3tqbUDEKLzxymE0FD0cR7cD mg511L//U+fXo2+dpsFFTgYDXAWq0qyYpvGqY0nbEXl5Y2nfIfq2fTX90yGaJCOh5yaS DPsTDo7cbejlvulxE7+DG2nQ87/eyvz/70wyWs9U65XgTik+qQRzOqd73dM6JnU4ABVh PPAGxH7GhRTvudJwnsWcziN44QVffdnVMjDQ74LaMGzxA1wIUdEX8A4gXCW2/FYEuuwt GHWOQ4T/v+z/GSPB/oadW+Vi9dq4/Uxn/YohxslZYrq/CwLeMdmxGAcDneIzcAStl3Ii aJaQ== 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=iAgHyuqeyLfY96j1CDmYgtEkSis4YZ/Sakdh5if7Be8=; b=vyD+BaDVEMssEjd6EE91HiuugyFWDP3+Isz1eNlLA3py2Fi+6wGkQpbtUu3wurdkYK tkDZ+9Asb9ZwQoYYv9bp7tMt+6yhOHr8TxrWxz7LeHXYO9rv2cfG2bQPiSUIYo299FSP f+LsObdKclM8pGCFPGv24B8mmhUSLewIkRJD8ezOWVJPU/2lhE3fQPfzvxSy7Mu4I14H hYgOkrj/9GY/aagbIMur0KNOtx1zUnw39yHRRkpmhxyPq1nPHouEHAUBkYsuAPcCvdPG k/4IwYULxvHFwE6687LTP2TCMu8eSnRgb7dZ8lW9l7IY8oN28Z2de9gMYkYhC7LOwDT1 Jf7g== 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 fx1-20020a170906b74100b00960c27e06b6si10744018ejb.1043.2023.05.04.11.50.36; Thu, 04 May 2023 11:50:40 -0700 (PDT) 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 BD36968BF20; Thu, 4 May 2023 21:50:17 +0300 (EEST) 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 D8AA86802C8 for ; Thu, 4 May 2023 21:50:10 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 97503240177 for ; Thu, 4 May 2023 20:50:10 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id y1_f4WjOpCBd for ; Thu, 4 May 2023 20:50:08 +0200 (CEST) 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 99EB82404EC for ; Thu, 4 May 2023 20:50:08 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 51AAF3A01C0 for ; Thu, 4 May 2023 20:50:01 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 May 2023 20:49:20 +0200 Message-Id: <20230504184921.12749-1-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] lavc/tak: make ff_tak_parse_streaminfo static 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: T9CIgT/LFMyd It is not used outside of tak.c --- libavcodec/tak.c | 6 +++--- libavcodec/tak.h | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/tak.c b/libavcodec/tak.c index f26574c968..d1604dc9d2 100644 --- a/libavcodec/tak.c +++ b/libavcodec/tak.c @@ -92,7 +92,7 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size) return 0; } -void ff_tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb) +static void tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb) { uint64_t channel_mask = 0; int frame_type, i; @@ -135,7 +135,7 @@ int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size) if (ret < 0) return AVERROR_INVALIDDATA; - ff_tak_parse_streaminfo(s, &gb); + tak_parse_streaminfo(s, &gb); return 0; } @@ -159,7 +159,7 @@ int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, } if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) { - ff_tak_parse_streaminfo(ti, gb); + tak_parse_streaminfo(ti, gb); if (get_bits(gb, 6)) skip_bits(gb, 25); diff --git a/libavcodec/tak.h b/libavcodec/tak.h index 6069118971..5e43598de8 100644 --- a/libavcodec/tak.h +++ b/libavcodec/tak.h @@ -149,8 +149,6 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size); */ int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size); -void ff_tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb); - /** * Validate and decode a frame header. * @param avctx AVCodecContext to use as av_log() context From patchwork Thu May 4 18:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41469 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp600044pzb; Thu, 4 May 2023 11:50:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4kv9H9KccIpokk1fxoUpZJsPy1KnMuo3ojS8Yc5TD0br9sBDo1TJDehKiwhuJ7OB/ZLbDL X-Received: by 2002:a17:907:7f07:b0:94f:694e:b953 with SMTP id qf7-20020a1709077f0700b0094f694eb953mr7274517ejc.59.1683226222072; Thu, 04 May 2023 11:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683226222; cv=none; d=google.com; s=arc-20160816; b=yR7/lvB0j42P4O1nmC/rJfl6Al4x0Mcz+iYCfxeMsBMs3SHHkx0hpwAqoqWG6maTCP FjyMZ9Qik38ND8DCo9Q5ULcRqZE6Lb98EmZHRTD4tzh7u7V5ovYlmigecAE2cPTyfhz7 Nw0mu5YNwkYhXa0C9SUEDfML7GN1xF2iFTJHYQ4ah10/P6WokSBWgt7UmT4VbuJSreep zdY0gxAv4/s9gY3syk/fQClt9NFG7+TNb8gZiQtVd57/3GJndws2bin4hhwCRUSVPE/J hCXW5I3fR8wQ1KnsZ/koedNQWdkHcnwiF5gG4Jy4gg8nj7kLjZQP9wRQZQJUBvcqBm8b 77qg== 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=Cngyn0HnscD19KZsz6Sk/nPfI8MWdWY272lRC2Tb7oU=; b=juqEPcDVQDJyJ6mLbM6vRiARgjlDBaPMkp+NcjqT9sS4BnxkGm6uZWRLFgQv9I8F6A fxsZ6ODzmtrFhJGiG3j5qgG5O+dPZtOS3XNuUyS8wTjl4zMSJ902CGmcL7GK5uSwxUvO PtMm9oaKQ+GTzqYpAAQY3AdvmIphp5zYHY46ENRx47HQC1TA5uMzc8Iv64SePnmHBrRn tp18NpZPbSBANkAh5ds3MTW/z52jytpoRcGH/mYFDbXxSbQOKiQ3/iTr2D9tkKHtP6rh Mb/OrTTUqmV1DzhsAr1NSDD57fOabazs/FUra/uL7QkCvYci5C6+3n38PaCp+F2C3adR tF1A== 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 ay10-20020a056402202a00b00504a26aa3f8si3211618edb.422.2023.05.04.11.50.21; Thu, 04 May 2023 11:50:22 -0700 (PDT) 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 86326689B0B; Thu, 4 May 2023 21:50:16 +0300 (EEST) 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 B6EA26802C8 for ; Thu, 4 May 2023 21:50:09 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2BE162404EE for ; Thu, 4 May 2023 20:50:09 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ynOJAbRbNUDe for ; Thu, 4 May 2023 20:50:08 +0200 (CEST) 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 91EA1240177 for ; Thu, 4 May 2023 20:50:08 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5E0323A048F for ; Thu, 4 May 2023 20:50:01 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 May 2023 20:49:21 +0200 Message-Id: <20230504184921.12749-2-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230504184921.12749-1-anton@khirnov.net> References: <20230504184921.12749-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] lavc/tak: do not store invalid values in stream info 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: KktWkj2R+0KJ When tak_get_nb_samples() fails, it will currently write AVERROR_INVALIDDATA as TAKStreamInfo.frame_samples. The parser will then use this negative value as a frame duration, which leads to various breakage. Avoid this by returning the error code from tak_parse_streaminfo() directly and never store negative values in the parsed header. --- libavcodec/tak.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/libavcodec/tak.c b/libavcodec/tak.c index d1604dc9d2..628609b71b 100644 --- a/libavcodec/tak.c +++ b/libavcodec/tak.c @@ -92,10 +92,10 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size) return 0; } -static void tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb) +static int tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb) { uint64_t channel_mask = 0; - int frame_type, i; + int frame_type, i, ret; s->codec = get_bits(gb, TAK_ENCODER_CODEC_BITS); skip_bits(gb, TAK_ENCODER_PROFILE_BITS); @@ -124,7 +124,13 @@ static void tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb) } s->ch_layout = channel_mask; - s->frame_samples = tak_get_nb_samples(s->sample_rate, frame_type); + + ret = tak_get_nb_samples(s->sample_rate, frame_type); + if (ret < 0) + return ret; + s->frame_samples = ret; + + return 0; } int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size) @@ -135,9 +141,7 @@ int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size) if (ret < 0) return AVERROR_INVALIDDATA; - tak_parse_streaminfo(s, &gb); - - return 0; + return tak_parse_streaminfo(s, &gb); } int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, @@ -159,7 +163,9 @@ int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, } if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) { - tak_parse_streaminfo(ti, gb); + int ret = tak_parse_streaminfo(ti, gb); + if (ret < 0) + return ret; if (get_bits(gb, 6)) skip_bits(gb, 25);