From patchwork Fri Sep 15 13:11:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 43747 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca2:b0:149:dfde:5c0a with SMTP id fx34csp305726pzb; Fri, 15 Sep 2023 06:12:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5BVARcXLtV8eIp0rtuUjTC6S3v2/Xk4sJyTVBVo0DC9T/mY0uDDg/yCCIjNRItYm7WnuD X-Received: by 2002:aa7:c454:0:b0:51e:3558:5eb6 with SMTP id n20-20020aa7c454000000b0051e35585eb6mr1528371edr.3.1694783568882; Fri, 15 Sep 2023 06:12:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694783568; cv=none; d=google.com; s=arc-20160816; b=cdvLFUiRjTtn5i+cmOlC+WqIqq/Y8AIQQGbNdYSIIlZ4Ll+Sa79fQkr4Vc4Y9MvKJT 7cJQ0p2ZEJSVKig1Vy/zPyDjEAqHOLyr74I+ezg2e6nBpcrlNYN2zN3SZrctNKgkNOas MgBCNFlmriabiRKSs7q000YCxxVVjJhFOeC3hYIzEGbr/kp1w5JP1BaFAGMjbU8ypZcA XnrVv15KypIq4fVaIvVQodUBrc3urvzuw4HpjzfBygS/3NadBuyu/r7qRXKV7HNkH0+R OZAERxJw3ZLMu2Ld+LXxYe/4FveEBlLCtohF4bY/IMn3/AyaeOjmWJLbSMC0sWkQhMbL XDUA== 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=5JPshfNlHyBcEw0IS4okXqoeZ6ymM0SFrmUsnUrA+FA=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=ZNoHiWC4xR6v0rfV55mETPxCqguto8iBmYChygM6R6/YkC4WCYyxtKZYGdVgGF8sxa jWm1bWo0cJFHNhtof9TE5VHuXWXkmylvYQrX3ovgMZOM3tGtopg2Drlv7cH10JlxIeaF 2wV5OKum3Q6TH/FVVaDze3To1Z79bWioxYUthiD0A0eA2zWYanb9iWqPKQMxzy4f3Yr3 Y3U4AzKe8+bLtgTllEu0F+1nyGAqT4+n3cxm7acz0Q8rg2rjgu/9xFQ8bZmVzB2kJsa/ f5fh+vykROSSHCma3UQmBknlBoPzrR8MdnPlQInI807Juel7/n5iggODhLFyhPx3wtUU ozNQ== 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 s22-20020aa7cb16000000b005259d57fb82si3451267edt.3.2023.09.15.06.12.36; Fri, 15 Sep 2023 06:12:48 -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 9E86768C808; Fri, 15 Sep 2023 16:12:01 +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 C474968C7C2 for ; Fri, 15 Sep 2023 16:11:51 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 2968BFF807 for ; Fri, 15 Sep 2023 13:11:51 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 15 Sep 2023 15:11:47 +0200 Message-Id: <20230915131147.5945-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230915131147.5945-1-michael@niedermayer.cc> References: <20230915131147.5945-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/osq: avoid using too large numbers for shifts and integers in update_residue_parameter() 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: qRaVYKHprJ+9 The code should be changed to not use floats in the VLC parameters This patch merely fixes undefined behavior Fixes: 2.96539e+09 is outside the range of representable values of type 'int' Fixes: Assertion n>=0 && n<=32 failed at libavcodec/get_bits.h:423 Fixes: 62241/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_OSQ_fuzzer-4525761925873664 Signed-off-by: Michael Niedermayer --- libavcodec/osq.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavcodec/osq.c b/libavcodec/osq.c index e2a84657fb4..e7f11691d2e 100644 --- a/libavcodec/osq.c +++ b/libavcodec/osq.c @@ -152,11 +152,15 @@ static int update_residue_parameter(OSQChannel *cb) sum = cb->sum; x = sum / cb->count; - rice_k = av_ceil_log2(x); + rice_k = ceil(log2(x)); if (rice_k >= 30) { - rice_k = floor(sum / 1.4426952 + 0.5); - if (rice_k < 1) + double f = floor(sum / 1.4426952 + 0.5); + if (f <= 1) { rice_k = 1; + } else if (f >= 31) { + rice_k = 31; + } else + rice_k = f; } return rice_k;