From patchwork Sat Jun 4 10:35:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martijn van Beurden X-Patchwork-Id: 36068 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp5125258pzj; Sat, 4 Jun 2022 03:35:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAJcRUnyM5UlG0+jC2KjOji8QAnOLQErtBAneVX2jA248HRu436/CQIeSDLKRcP1UJrCTI X-Received: by 2002:a17:907:1b25:b0:6da:8206:fc56 with SMTP id mp37-20020a1709071b2500b006da8206fc56mr12572365ejc.81.1654338946334; Sat, 04 Jun 2022 03:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654338946; cv=none; d=google.com; s=arc-20160816; b=XMGahVMWCPv53EAvYFU1bRKfZiLzV/B1qGpTZavC215RQtGpF0JjQizgeBjjBWyKrG 631zx/BofZGTO/oxnvSoqpAgmVUXu+omUswSEMjq+SGFAG9g8t3PMzLSMnYsJJQsXtuL o3Bx+5Z3KLoSMnBjrfl/Dij+fEvO0mnJpV6RxHQ4Fgti7xanApcR59gXocM/wm00pphz 1IUEB2mBQxvSBi9KFZ13JCYXQAqsYGejRKOD4uDc4kZ0y3W4PGPgtqCBMcyBLjwJc/Jf cx8gNCCy4h0aOrAhHmExNhN6vEcckrHamjiXUQxLSNUXaHKwV297xxBe4WgTAcnL/GTU +AiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=5uTVEN1b9rageoO1hBi8BcAt+b/zbHE1OoUF70fywGM=; b=jyV+wIiZKpz6dfNdzE+dP4yWU3NUIXpHMZKwOBcgQC2uOueHHm0CSLVpWuCnA9VeJd wXY3OFfoExvgymNtJO05skZCIMP9TvJS15zn4PsSyiV3HKVBtUW42Ez21qhm+x/MXtjH x7VHaLKcs7LjuClt/+W2nRnwEAHTikIw4mytBjMjGu6jfmhcIZ6zSGDAG5n4gcfGvkvk kVdlcpRVqlaqZB4GUy1uRBC1Ls4wGD8rcMDIqS/b2aIVldK81uuNdzpWo42lcBt+7q0R vshXihCJ0mBAuGoB26H1trcWVq8LOo/lhaXQ4qRzlMYPLPSEtoQd13CMLr4aloLXlo1u /flw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="qukptu/Q"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p33-20020a056402502100b0042df4e01f3dsi10553002eda.414.2022.06.04.03.35.45; Sat, 04 Jun 2022 03:35:46 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="qukptu/Q"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BA09F68B3BB; Sat, 4 Jun 2022 13:35:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C8DCF68B536 for ; Sat, 4 Jun 2022 13:35:34 +0300 (EEST) Received: by mail-ej1-f44.google.com with SMTP id me5so19745133ejb.2 for ; Sat, 04 Jun 2022 03:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iTflgv8UDa0NJ6lqhTV8hZLbLufZWVCeqm0Gkq4sg+A=; b=qukptu/QWA0fQjcJGPaewcnHKPnL6qZUP9t1tRHG/rcihxLWNZVuBSXuDiOCJG9A8t hgo6Xb8nlB9JDGtREhaA/3P0ngJmAk9q/aptBNEot0fnWxuATq4B0O8BE2H02P4zMT7Z UXjnm1WYSw3tdXl0QxamA6Jm/7PQjzoVwk6F70PKr0/bt8aBHR2iUY7d7r4zHHNgqvxq kAUcaqTFK/5XMQdCyElEerq8zj+NF5KZeqUnv6jaeJdfBJQve/LFZgm1yJ+bS6TrdC3m kVUOdAHU7IqdBO8axn30X+HiVRntZ3Yf+VV9aAiv1JxAsSTJUBPcs6cd7yfUAcqj46ot mCHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iTflgv8UDa0NJ6lqhTV8hZLbLufZWVCeqm0Gkq4sg+A=; b=stCcLF+ZUIQIXZ73s9HXZ5Inc35TfbHHeM8PTGl5dTgQC/7lf1vksbljjvM9ktYTkw szTOXcosM0P/iwGT8b22SSWQ9aov7h2e95NNbn0EHWGdduG5vLYJpteZCJ+lisGEm4sa SlSbFqF7mceS+VYnAZVo8wU0f6+dIGxVSPNJCgpdx1PnDkiJdElABKocFtiA+fkSVKIQ pjPLxVw8vg2rAsYAy47Qn8Vs8w/oyGGk9TOoju893wrBPonnRSWLQZKriZ/zLVnTe0pP BUAYCR5qR9PwOKKKMi2c2PyR318hEnvaxPOyLDWffu62r1kP2251IT1+wd6lVbFF1Hmp wMVA== X-Gm-Message-State: AOAM532QJK8JSv2wA5vaKvzqZiQ9P4igJ2FiRjzQf3r1kyfITinZ18c1 bxYCXqoPgw45/LBz/oPBzWR6IcuVzN6fdA== X-Received: by 2002:a17:907:7d88:b0:6fe:d709:6735 with SMTP id oz8-20020a1709077d8800b006fed7096735mr12243823ejc.76.1654338933882; Sat, 04 Jun 2022 03:35:33 -0700 (PDT) Received: from localhost.localdomain (92-64-99-37.biz.kpn.net. [92.64.99.37]) by smtp.googlemail.com with ESMTPSA id h1-20020a170906590100b006fe97996423sm3793743ejq.219.2022.06.04.03.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jun 2022 03:35:33 -0700 (PDT) From: Martijn van Beurden To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Jun 2022 12:35:06 +0200 Message-Id: <20220604103507.1822192-1-mvanb1@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/2] avformat/cafdec: Implement FLAC-in-CAF parsing 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 Cc: Martijn van Beurden Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bGwAq16THtTi The afconvert utility shipped with MacOS supports muxing of FLAC in CAF, see afconvert help output on a recent Mac here: https://hydrogenaud.io/index.php?topic=122509.0 A file created with afconvert free of copyright (licensed CC0) can be found here: http://www.audiograaf.nl/misc_stuff/afconvert-FLAC-in-CAF.caf This patch implements parsing of such a file --- libavformat/caf.c | 1 + libavformat/cafdec.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/libavformat/caf.c b/libavformat/caf.c index a700e4055b..a61c39fae5 100644 --- a/libavformat/caf.c +++ b/libavformat/caf.c @@ -46,6 +46,7 @@ const AVCodecTag ff_codec_caf_tags[] = { { AV_CODEC_ID_GSM, MKTAG('a','g','s','m') }, { AV_CODEC_ID_GSM_MS, MKTAG('m','s', 0, '1') }, { AV_CODEC_ID_ILBC, MKTAG('i','l','b','c') }, + { AV_CODEC_ID_FLAC, MKTAG('f','l','a','c') }, { AV_CODEC_ID_MACE3, MKTAG('M','A','C','3') }, { AV_CODEC_ID_MACE6, MKTAG('M','A','C','6') }, { AV_CODEC_ID_MP1, MKTAG('.','m','p','1') }, diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index 168f69f20b..a9e19df264 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -32,6 +32,7 @@ #include "internal.h" #include "isom.h" #include "mov_chan.h" +#include "libavcodec/flac.h" #include "libavutil/intreadwrite.h" #include "libavutil/intfloat.h" #include "libavutil/dict.h" @@ -170,6 +171,49 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) } avio_skip(pb, size - ALAC_NEW_KUKI); } + } else if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) { + int last, type, flac_metadata_size; + uint8_t buf[4]; + /* The magic cookie format for FLAC consists mostly of an mp4 dfLa atom. */ + if (size < (16 + FLAC_STREAMINFO_SIZE)) { + av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n"); + return AVERROR_INVALIDDATA; + } + /* Check cookie version. */ + if (avio_r8(pb) != 0) { + av_log(s, AV_LOG_ERROR, "unknown FLAC magic cookie\n"); + return AVERROR_INVALIDDATA; + } + avio_rb24(pb); /* Flags */ + /* read dfLa fourcc */ + if (avio_read(pb, buf, 4) != 4) { + av_log(s, AV_LOG_ERROR, "failed to read FLAC magic cookie\n"); + return AVERROR_INVALIDDATA; + } + if (memcmp(buf,"dfLa",4)) { + av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n"); + return AVERROR_INVALIDDATA; + } + /* Check dfLa version. */ + if (avio_r8(pb) != 0) { + av_log(s, AV_LOG_ERROR, "unknown dfLa version\n"); + return AVERROR_INVALIDDATA; + } + avio_rb24(pb); /* Flags */ + if (avio_read(pb, buf, sizeof(buf)) != sizeof(buf)) { + av_log(s, AV_LOG_ERROR, "failed to read FLAC metadata block header\n"); + return AVERROR_INVALIDDATA; + } + flac_parse_block_header(buf, &last, &type, &flac_metadata_size); + if (type != FLAC_METADATA_TYPE_STREAMINFO || flac_metadata_size != FLAC_STREAMINFO_SIZE) { + av_log(s, AV_LOG_ERROR, "STREAMINFO must be first FLACMetadataBlock\n"); + return AVERROR_INVALIDDATA; + } + ret = ff_get_extradata(s, st->codecpar, pb, FLAC_STREAMINFO_SIZE); + if (ret < 0) + return ret; + if (!last) + av_log(s, AV_LOG_WARNING, "non-STREAMINFO FLACMetadataBlock(s) ignored\n"); } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { // The data layout for Opus is currently unknown, so we do not export // extradata at all. Multichannel streams are not supported. From patchwork Sat Jun 4 10:35:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martijn van Beurden X-Patchwork-Id: 36069 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp5125332pzj; Sat, 4 Jun 2022 03:35:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+HUqvA9J04K0w7ra9J19WP8kdowYbqFSaFzl9g8ZZihkw38MZEPLjnI3ROGbf6KhXbITh X-Received: by 2002:a17:907:c202:b0:710:8d0c:6e89 with SMTP id ti2-20020a170907c20200b007108d0c6e89mr2503260ejc.141.1654338958057; Sat, 04 Jun 2022 03:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654338958; cv=none; d=google.com; s=arc-20160816; b=wEFzBFhrijlvbcbBA5bIJq6c25rv2BXNF91Kucn4qm0gdX9JPIK/ve+yBRDwmCsYOP A6HiiE/gBekU2d70RdDLBx498y6QUHWuTs1KMtEB/RfUxBAsvmEqjp8Q52hQNhCfQ8Vd jmV3aCKjYPw5ToB7j7PnkBvAiSHFDwlksugFVD7PqAuCx0qe/eDZ7iPFlhF1E2lIZcpJ qx+OzAjZVyqrZ4ZmsPVyvR+i1U9/UwaLamkTjC/Hc8wQH7pdXuORMeyNUvGCz+pDIdqd Q2tT/xy1Y14Kq1vm0VUzYQiH5R1IhfhDZ4YB0ZEz+ydtr7qnTG5HXctS5bCjAmX8tDpC aJAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=s/aBSjXFiLDu+kh3a92PUGqTISKgsf+9lv96WlmJXfU=; b=sEiNnRBFsAXrXoVXMMPhulCTWpIRjw993QUmyxF/1+Dwbz9qhMG19DrmMSeMfqHHK1 PXVwRanKDGf6JZbzYRNidaPtj9V0Irl5zheOjdKE99qND80jFaMiO1HDo98VRuoHzfwO F+5BEYx9CB8ERryZWNNqVQO672KCZDYxhE6kItCePASKjHodQdGPZ1Iw+IeFOsuREHzu 8Y8Rr+uV8e7BY5tzXhYImrQWzSXkvcQ7g20jmN2NzFMYBYAU7hfa5dFdzsMo9scFi1HS l6wS14YxNr+gatFxsw24k5tsIFzWXBOTKorBuLJIE+z6G8wfAkGLDMuuLa3C7MdRSAh0 di7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=i6KMZYDv; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g14-20020a056402090e00b0043137319d67si390879edz.324.2022.06.04.03.35.57; Sat, 04 Jun 2022 03:35:58 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=i6KMZYDv; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C9DDC68B757; Sat, 4 Jun 2022 13:35:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 59A6468B58F for ; Sat, 4 Jun 2022 13:35:39 +0300 (EEST) Received: by mail-ej1-f54.google.com with SMTP id h23so9189391ejj.12 for ; Sat, 04 Jun 2022 03:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SNyk9CHuGP3MtbxzoY5/flDxd9gdD3osHzenTFRYAuo=; b=i6KMZYDv3Po1w7YaWyja0qNFTvkkG4E9vvLM7nbkIRIbdSCwjf+uY6fl4aRS2XDnH1 POWSUm6lmsh3KmIqBW8TO9sKLAE0HzrsutUJq/ns2af9y0IRIBlI+tFDBkUDve9fodHL 95W8FTMLs2Jl4WYvlVLfaGWYvY75AfFB3ewmK6BSTBXgGpB9CCyxVW6Bdy3BUTM1Xr5r uxA+41dnoxhGrxfBXMKf4N1uQbn4ZoDT3Oo7Hg9g8kg4rD1cA1ZsUv+EAIXigBhjrGI1 4C3T1+RwUPa4v05VKeoovAx1Dhzx5dIAG8W6zNpyYp9DffTRfLXh5jIBfVkDPzmHZSPl Rwqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SNyk9CHuGP3MtbxzoY5/flDxd9gdD3osHzenTFRYAuo=; b=oZQ3Q2mxdXx5qBym15GLRAom5reMB9ROJJ7ELm84Ea1hQuCmWDHuqajzfB6v250HSn VfPxZZ12VeZOV7Amby0+isDpL1VMNmrdeBEArbCBVcveASgqhdJUZ61yPbRL46vL7/qt 4bQD3tocJ+HPy7w8lbcKvHFskd1RN+WLKXbvn+WfoSLbuQ8xWcGdAPSJHh7RQ9yLFojl lDo1WtBuWdG0euVr3eEunopm9bYrEdo8evV8h9KkXXzy4f2uUrZav5QbzFHmx+tVqcLy Q0PSTx9wwFlP2aJqyXRQrv1QPvHG4cDSo9MivgpV14uOD0dXCy4ZOWtwkoAbPUQ8BO9d p6NQ== X-Gm-Message-State: AOAM531F+Weq1XFGmJ3t2p19hGMRMArXlnvWMPVW4kTmH+OV4I++jQjR rR/dCAHmZ8LQ9tgWYHOKKIuDz7IinAx+lg== X-Received: by 2002:a17:907:e9f:b0:6ff:3a0:cdfd with SMTP id ho31-20020a1709070e9f00b006ff03a0cdfdmr12961565ejc.448.1654338938527; Sat, 04 Jun 2022 03:35:38 -0700 (PDT) Received: from localhost.localdomain (92-64-99-37.biz.kpn.net. [92.64.99.37]) by smtp.googlemail.com with ESMTPSA id h1-20020a170906590100b006fe97996423sm3793743ejq.219.2022.06.04.03.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jun 2022 03:35:38 -0700 (PDT) From: Martijn van Beurden To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Jun 2022 12:35:07 +0200 Message-Id: <20220604103507.1822192-2-mvanb1@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220604103507.1822192-1-mvanb1@gmail.com> References: <20220604103507.1822192-1-mvanb1@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/2] avformat/mov: prevent potential use of uninitialized 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 Cc: Martijn van Beurden Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: r3YwzdX/DGJd --- libavformat/mov.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index d7be593a86..f3a63abaaa 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -6772,7 +6772,10 @@ static int mov_read_dfla(MOVContext *c, AVIOContext *pb, MOVAtom atom) avio_rb24(pb); /* Flags */ - avio_read(pb, buf, sizeof(buf)); + if (avio_read(pb, buf, sizeof(buf)) != sizeof(buf)) { + av_log(c->fc, AV_LOG_ERROR, "failed to read FLAC metadata block header\n"); + return AVERROR_INVALIDDATA; + } flac_parse_block_header(buf, &last, &type, &size); if (type != FLAC_METADATA_TYPE_STREAMINFO || size != FLAC_STREAMINFO_SIZE) {