From patchwork Thu Oct 12 23:27:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44233 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4b15:b0:15d:8365:d4b8 with SMTP id fp21csp660409pzb; Thu, 12 Oct 2023 16:28:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEf5Xr65G0EJ/rH2d7YzxvOIOQ4+j9GDqN36QdLUlAIGfybmCcoWY9eGYVPSTTZOKzukFu0 X-Received: by 2002:a17:906:3ca1:b0:9a1:891b:6eed with SMTP id b1-20020a1709063ca100b009a1891b6eedmr20583075ejh.76.1697153291123; Thu, 12 Oct 2023 16:28:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697153291; cv=none; d=google.com; s=arc-20160816; b=SBDfm033x37iipIOALw+HPT83EbGOOGfwYFMFkC6lvQ9aJa7BXoDo4fSAPlx/RCB14 HYWOIfEEPkxzVzY1a4V3V81275SkjejmpvvLu6p6EmMhke4PQea6LKoqVNPdIP1acsPK JveX8eTh6sAl5xCgS0AmwpFx4qDjNJ4l1bmQ4nT6WDVVEHrN3uUgY7XWvH930u76kLae a87Rro5NcYLkLQQlHR/9gmYB3muvv+xV+0xtouQMq64ekdQNVumS6Vz6ChBrBOvzjU6g noRXYGfuIyvIYp23rO72sWEfQQmsgE9r0iIE80Ybnfr7+p1LA/8GrPzkUBY4277ExlDK eCng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=+/mOmTOfT62ezU9C1RgHYZqvJ04IPIyG3G2UE2iOPp0=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=aMtGqTC8oG/a9Ig2V69b9bQz9uan5rZeOjm7FINlnOZBVZ/wSIB+GxqxNJgNrx8qSf birIOt/HYfDj1h99tVfS5pgXcTRSSWDd5LtzbDjKQLZsKPZ380eTJnDYDv9cH8c4P421 zm0e9R96GeaECazeLuoLWaUVnO9fCCenac9YoVnUaFlogalzQGyrI9h3PK8b3u0lO9Vx 5cD/bL/6VUYM5gWSqBS+ALGiSwPZ5mPSgMoxSGglUaHK0PmvSH3VUWMVSv1WW69S63kk hGaO01NdUWVBmYrmosEsNRcla8RyA/aB3bJEEKr6i3DSbdcjt/dqd6PWMUpRk7trah7V 52fQ== 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 by21-20020a170906a2d500b00992bf74c31csi7844714ejb.1005.2023.10.12.16.28.10; Thu, 12 Oct 2023 16:28:11 -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 35B5E68C9BE; Fri, 13 Oct 2023 02:28:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 059A368C76B for ; Fri, 13 Oct 2023 02:28:00 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 24D8CC0003 for ; Thu, 12 Oct 2023 23:27:59 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 13 Oct 2023 01:27:57 +0200 Message-Id: <20231012232759.5352-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/evc_ps: Check chroma_format_idc 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tVaGFVirQc+h Fixes: out of array access Fixes: 62678/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-4858264984354816 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/evc_ps.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/evc_ps.c b/libavcodec/evc_ps.c index c11b92d1c5..19895d404d 100644 --- a/libavcodec/evc_ps.c +++ b/libavcodec/evc_ps.c @@ -179,6 +179,10 @@ int ff_evc_parse_sps(GetBitContext *gb, EVCParamSets *ps) // 2 - 4:2:2 // 3 - 4:4:4 sps->chroma_format_idc = get_ue_golomb_31(gb); + if (sps->chroma_format_idc > 3) { + ret = AVERROR_INVALIDDATA; + goto fail; + } sps->pic_width_in_luma_samples = get_ue_golomb_long(gb); sps->pic_height_in_luma_samples = get_ue_golomb_long(gb); From patchwork Thu Oct 12 23:27:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44234 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4b15:b0:15d:8365:d4b8 with SMTP id fp21csp660467pzb; Thu, 12 Oct 2023 16:28:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhm9h8njT/PtfrnN8T2SPTG2+wucSCBCPZperXHiPp8TCZ1vob1oQNzH0O5iImF8jNpKQG X-Received: by 2002:a05:6402:ea2:b0:53d:af60:219f with SMTP id h34-20020a0564020ea200b0053daf60219fmr7233924eda.10.1697153300332; Thu, 12 Oct 2023 16:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697153300; cv=none; d=google.com; s=arc-20160816; b=JwJ/e5BADsPbk51/LPaJzvvjNQdwalpQfN39ob7FTsA922WvLnxIHynZK06YkrLVoL 8rQFJO7T1gf5telpnTOARJjCGN/a9Ky49jYfHzyMDnNsz/KIMh2I5ednrZYYx4pOorGS edpyxH7IkYR9RG2LyAHDVvrpQqkP95FWB2mzgWI1B30tyKZAPtq+4zuYbWe3A+swXqKL /P1vLxctSdZ/NiCFCSEwZQQ2i2S7rL0p/V/WJv9kfT26m1yxEjaopKrWLwnnUoHRgee9 0aLPGTf+acZ5OrGfdNlECKyma4+Rqq0rWWcWxmSYrrYARpoWenYNcGKGDOihMm7PmHr5 jXuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=eCovw9iiS4hbOxRRHnsdsj2UoLnPEVUz21EWh6dRgGY=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=ZED0V4RHSe8JIQ9nhmYD3q0R4SmZ3boQ/a4ekmGoetN4gMhCZApnGXeKK/POPAhAS7 AunbtBPm5kjPJHtypDvmYtyvknHKrS2xF446TXm5N/RuMIaD6hrWKNcNrUdFzOUCCobA FVwnJ1QoHoLn4n2xnxKDT18ySzzGO5qTKbbm2qALeXV5BeRUc81yRvaBOZhwZnMPHhy+ hAopD1kGI++7pDgVZEDeJFmvzozPUMumKuZKeboskDzIutpiZGH+4eqq6PY11n8N3INl fv/XMVxmzv3QoiUvag3fs6hm+NilUh9j0tJb1yjSRh0y0lUygOU+FBbadDggpvXMYIC+ 76Jw== 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 c18-20020a056402121200b0053dff300911si1472097edw.376.2023.10.12.16.28.20; Thu, 12 Oct 2023 16:28:20 -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 31B0568C9E5; Fri, 13 Oct 2023 02:28:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E423468C9BE for ; Fri, 13 Oct 2023 02:28:01 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 37A16FF806 for ; Thu, 12 Oct 2023 23:28:00 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 13 Oct 2023 01:27:58 +0200 Message-Id: <20231012232759.5352-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231012232759.5352-1-michael@niedermayer.cc> References: <20231012232759.5352-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/evc_parse: remove pow() and log2() 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: UmLjyqwfiI/v The use of float based functions is both unneeded and wrong due to unpredictable rounding Signed-off-by: Michael Niedermayer --- libavcodec/evc_parse.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c index bd3a4416f2..255706ce61 100644 --- a/libavcodec/evc_parse.c +++ b/libavcodec/evc_parse.c @@ -172,7 +172,8 @@ int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh, poc->PicOrderCntVal = 0; poc->DocOffset = -1; } else { - int SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length); + int SubGopLength = 1 << sps->log2_sub_gop_length; + if (tid == 0) { poc->PicOrderCntVal = poc->prevPicOrderCntVal + SubGopLength; poc->DocOffset = 0; @@ -187,15 +188,16 @@ int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh, poc->prevPicOrderCntVal += SubGopLength; ExpectedTemporalId = 0; } else - ExpectedTemporalId = 1 + (int)log2(poc->DocOffset); + ExpectedTemporalId = 1 + av_log2(poc->DocOffset); + while (tid != ExpectedTemporalId) { poc->DocOffset = (poc->DocOffset + 1) % SubGopLength; if (poc->DocOffset == 0) ExpectedTemporalId = 0; else - ExpectedTemporalId = 1 + (int)log2(poc->DocOffset); + ExpectedTemporalId = 1 + av_log2(poc->DocOffset); } - PocOffset = (int)(SubGopLength * ((2.0 * poc->DocOffset + 1) / (int)pow(2.0, tid) - 2)); + PocOffset = (int)(SubGopLength * ((2.0 * poc->DocOffset + 1) / (1 << tid) - 2)); poc->PicOrderCntVal = poc->prevPicOrderCntVal + PocOffset; } } From patchwork Thu Oct 12 23:27:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44235 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4b15:b0:15d:8365:d4b8 with SMTP id fp21csp660515pzb; Thu, 12 Oct 2023 16:28:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUDHJc+3CV7nN9qNYKYD8Mdic8QbhwbDN+cLxGqDb7o6puTAFpbQUP31Fq0vROxKn+QiVX X-Received: by 2002:adf:d1ca:0:b0:329:6dbc:e9a8 with SMTP id b10-20020adfd1ca000000b003296dbce9a8mr19866633wrd.8.1697153308046; Thu, 12 Oct 2023 16:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697153308; cv=none; d=google.com; s=arc-20160816; b=XgF2WvXXUGXlQgPtef9UrYZg+xVO64K0Gj+AiIaKZ6+9EYtEXqKUjfXkMKxYiXiNjc ySMi3rPU9Y9sVql7Mcc+8t0ZtK5kNOZn/Pvo1uB7Q3rBYLum3RcVs6o9qEvHMBJpkXDB 1XAGOm3iLmWqBmTjsBFgxXGDVKKku2RLAFanV4wJGyk9nDIJ+Lo4t/8m5Iqld/vT8hk0 juz/LarK6wXrpSQbRWzscfuxZYPevGBtv8wfATSr/afHPo8FLkWuEh6809F6FJT7kU00 559td4xQTRgJcSBdkmBbSupJzpCFRnoh3a6Ui6OV8Qa8SbqH+dBJyn2Gu0YQBTwRUZW7 mjhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=WkmFiC8aAg0KmyzYRsh+hJUSgPk3vNTbVHs2GHav7Pk=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=BUgCULb0L4ZHsKtB7hXo0ta37lLhMVtJKg8fRb23OT9LwiALIz4QofhIyclEZEnAHi i1eokP2zbaFeZeMwrJNKK5cTLs5D+RlGfd2CKk7soDmEZPO1XRnjmDrPxWU9ICJ+jENs 446bPgw0f+7JMn65BusJoqeka9gDaVo+jcz7jck/NIbr4jKqhgaf/9FxRjF0Fg7cWV2h s82SUs1AbFm4KLy3Tqu70QWZ9f04m6D1PvxDesc8Dxeqg0RGNzBI/5PZwqJhI5vhDZgy xWt8yhQSqmn6UwbYvwzQ0NWjOW6hOft5GU+Ixe08bYPdSCwcLn3OyX/hNcFC4m0FCG4O qJGQ== 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 g20-20020a1709064e5400b0099bd53a0d3csi7895900ejw.178.2023.10.12.16.28.27; Thu, 12 Oct 2023 16:28:28 -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 2AC9B68C9F8; Fri, 13 Oct 2023 02:28:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 324B568C76B for ; Fri, 13 Oct 2023 02:28:03 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 7F6621BF206 for ; Thu, 12 Oct 2023 23:28:02 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 13 Oct 2023 01:27:59 +0200 Message-Id: <20231012232759.5352-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231012232759.5352-1-michael@niedermayer.cc> References: <20231012232759.5352-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/evc_parse: Check tid 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: z6WiNjnes2h2 The check is based on not infinite looping. It is likely a more strict check can be done Fixes: Infinite loop Fixes: 62473/clusterfuzz-testcase-minimized-ffmpeg_BSF_EVC_FRAME_MERGE_fuzzer-5719883750703104 Fixes: 62765/clusterfuzz-testcase-minimized-ffmpeg_dem_EVC_fuzzer-6448531252314112 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/evc_parse.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c index 255706ce61..43b8dabf8b 100644 --- a/libavcodec/evc_parse.c +++ b/libavcodec/evc_parse.c @@ -174,6 +174,9 @@ int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh, } else { int SubGopLength = 1 << sps->log2_sub_gop_length; + if (tid > (SubGopLength > 1 ? 1 + av_log2(SubGopLength - 1) : 0)) + return AVERROR_INVALIDDATA; + if (tid == 0) { poc->PicOrderCntVal = poc->prevPicOrderCntVal + SubGopLength; poc->DocOffset = 0;