From patchwork Fri Jul 19 03:10:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 50640 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:a742:0:b0:482:c625:d099 with SMTP id f2csp353639vqm; Thu, 18 Jul 2024 20:10:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWSblakwiVwKhiCoCSJxQFZwXuCY0VTDKqIRPm5+D/0HMDc35eBy/VqlA5yz4NkAiEE0/sjp0McfANivTr68Mbzp8n0id3zNtRl4A== X-Google-Smtp-Source: AGHT+IG/BDfL1wpiy9+U3PlH8cCI/8DF94+EhvmxV4nQjSPGghkOFgGXwhcbw0GNpvY2ALC0Miky X-Received: by 2002:a2e:be25:0:b0:2ec:565f:ef56 with SMTP id 38308e7fff4ca-2ef05c57379mr35104581fa.7.1721358645134; Thu, 18 Jul 2024 20:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721358645; cv=none; d=google.com; s=arc-20160816; b=xYRSzOyjGSDJZzT7PYzQvVZ0AkyzDxDQepwyvk9EoyhPHE4cCpqfsQXpZAmZP7LRxr 4zTwrl53Un8kcFN9n79G750xmJHPOGoyrmrjFno0uwqeaDv6UAx4cFG47DfiRPnY5teM HI426uNuU8ylHFM/sSdjXhRcqj0AoIPhEfyQhx+3HNY6qIRS3TEJNC4YzcMdqp4pBHgV mJPZou2YG9MT6TO6wUguu9vSvJCwPbO4jsEtxSFQTH51SfLTyaxNU1BPcqo+2OYlRvlZ Pv3x4ixZ62lMPXRo9p4kGuhL42UE3CSY1EgL6Ukc0rRuZlZ/vQf8N0NSTHhCxHquwYU5 B0UA== 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 :dkim-signature:delivered-to; bh=rL6eBxLsVVGfIyFgR5woInS1kh2PvSXaD451TPkFPdQ=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=BjibfBh+XMVoEySfIehpCPF8FsROeuznsSSxQMIgX3Ihh/vqeZmplzuceLNaUdpnAz njbiBkuFjGTcvuyyGJPymR1BLwtsjD+jRCsGhG7cTBgFz5rZTgFGMJQV7HodFMUWLNPF T7gdwG23A3oU7q0228zMtNKuFo4Hz6608xqP+svNQIBbsTlMrPBxwKRU8PcKP4QfBvEc QXbSs0AwxJj5ntDsy5yt9d2tV4HdOSM3O10NbDuNJGuXHBBtcladgkI1dx7yQGHjyZTX j+vSN+BlQl6hoz4e1eFbND6uYtkJeIqDhFL8EFOAItQq8+gxUWn40VB4saMquJ2Vxc8T rVSA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=XdeGwE9x; 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; dara=fail header.i=@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 38308e7fff4ca-2ef0fce9dd3si1107111fa.308.2024.07.18.20.10.43; Thu, 18 Jul 2024 20:10:45 -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=20230601 header.b=XdeGwE9x; 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; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EBFF568DA16; Fri, 19 Jul 2024 06:10:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE29368D684 for ; Fri, 19 Jul 2024 06:10:32 +0300 (EEST) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-70af8062039so362642b3a.0 for ; Thu, 18 Jul 2024 20:10:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721358630; x=1721963430; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=at9LZ/YmhseYemtLajOIE+aI0gJv8iNHEOfF90rcJAg=; b=XdeGwE9xwMtzPmokJhSsuoRzewqNjCdXal6qNUjfIYXBdhVOWqI5K6hh2vc88CHhRB s1m6RAKcDS97bPzRu/TzZkdfU92KbAEpkhGsrPj6xL1sv96GpPnROTgQhQnreFPS6t+h qSNHonTE8bG+8nrWtP6mDxrWFOeFGrPc9Hr1ire4GUFtX0TUht6VXc62/uvU6x+kBmFv m5HK0g4m2csp2FIkh1JKXwg7ZULIAnZhbWPH2wfkAzlQE1J4FDP7c9hG/K+x+pMqV6Gu v4oOhti3zpQWsQ0U0Quq3kr1vXYMSLEy7dELkJ2gudOdl5AUdyB4rh+YncdmSxyTgv+v DTBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721358630; x=1721963430; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=at9LZ/YmhseYemtLajOIE+aI0gJv8iNHEOfF90rcJAg=; b=knEarf3vIDCm3ktJw0idg7T+KEGN86yQ+RuIqj/nUCTjId7QkK12/0ncS/WDAKaoNk 2rLNf6saWJ3wCY95j1jCgUXlgk+oJ58XreCPxs5U3ulZUiQeZ3V8cUz6ADmcmlBGoU0b j+EEMVOeGrFSBjc5n+DRi4Eo6bglCUIZBVCGXuPv3uuGSSM53BJm39LQPABgY14UKmAx mXEFI9ntQ8obr6fvinGQIFjmdzUGOh/FkigekX75UJWPyeuck5RnFGMpi8fJL/FS3awk fsII1aFhY7XU/ng0mvHEwCHia2b8f/w1rqOxrKby+fMBa5aNbwwH7DtVEdtmHsUf8+Vy xuLQ== X-Gm-Message-State: AOJu0YztOMqNXVptSXb4AByknbV8b5r5bIWYV4RbVDzmz/WHitcCqyXo EoxPkVwTtv7MasIjSTBS2jpTq59JGZWTeYWJrFgdCPjDpjU+zlIXep6WCQ== X-Received: by 2002:a05:6a00:2d29:b0:706:a8fd:43db with SMTP id d2e1a72fcca58-70cfc8cac40mr1760714b3a.4.1721358630118; Thu, 18 Jul 2024 20:10:30 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70cff492ff7sm271773b3a.17.2024.07.18.20.10.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 20:10:29 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Jul 2024 00:10:39 -0300 Message-ID: <20240719031039.18794-1-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/iamf_parse: sanitize audio_roll_distance values 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: b1sQQNqJZsbM Ensure the values are spec complaint and that no integer overflow can happen. Signed-off-by: James Almer --- libavformat/iamf_parse.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c index a176c7d13a..dd394c5564 100644 --- a/libavformat/iamf_parse.c +++ b/libavformat/iamf_parse.c @@ -38,7 +38,7 @@ static int opus_decoder_config(IAMFCodecConfig *codec_config, { int left = len - avio_tell(pb); - if (left < 11) + if (left < 11 || codec_config->audio_roll_distance >= 0) return AVERROR_INVALIDDATA; codec_config->extradata = av_malloc(left + 8); @@ -64,6 +64,9 @@ static int aac_decoder_config(IAMFCodecConfig *codec_config, int object_type_id, codec_id, stream_type; int ret, tag, left; + if (codec_config->audio_roll_distance >= 0) + return AVERROR_INVALIDDATA; + tag = avio_r8(pb); if (tag != MP4DecConfigDescrTag) return AVERROR_INVALIDDATA; @@ -118,6 +121,9 @@ static int flac_decoder_config(IAMFCodecConfig *codec_config, { int left; + if (codec_config->audio_roll_distance) + return AVERROR_INVALIDDATA; + avio_skip(pb, 4); // METADATA_BLOCK_HEADER left = len - avio_tell(pb); @@ -146,7 +152,7 @@ static int ipcm_decoder_config(IAMFCodecConfig *codec_config, }; int sample_format = avio_r8(pb); // 0 = BE, 1 = LE int sample_size = (avio_r8(pb) / 8 - 2); // 16, 24, 32 - if (sample_format > 1 || sample_size > 2) + if (sample_format > 1 || sample_size > 2 || codec_config->audio_roll_distance) return AVERROR_INVALIDDATA; codec_config->codec_id = sample_fmt[sample_format][sample_size]; @@ -246,6 +252,12 @@ static int codec_config_obu(void *s, IAMFContext *c, AVIOContext *pb, int len) if (ret < 0) goto fail; + if ((codec_config->nb_samples > INT_MAX) || + (-codec_config->audio_roll_distance > INT_MAX / codec_config->nb_samples)) { + ret = AVERROR_INVALIDDATA; + goto fail; + } + c->codec_configs[c->nb_codec_configs++] = codec_config; len -= avio_tell(pbc);