From patchwork Tue Nov 22 10:26:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 39385 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp2908081pzb; Tue, 22 Nov 2022 02:27:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Ma3kuXMUJ504zVSa1mUWFOTAnLBfCROq3xuB4hSRyoNwwcJraNRe+fgs3TTDGkHca0FZz X-Received: by 2002:aa7:d3cb:0:b0:461:8d98:3d6d with SMTP id o11-20020aa7d3cb000000b004618d983d6dmr6660878edr.116.1669112822974; Tue, 22 Nov 2022 02:27:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669112822; cv=none; d=google.com; s=arc-20160816; b=ju3F/lvWgQsqqNeWetvQf17moYtmveB5wr38VCvDwmQIkaO22Yu++JvL1c31teL0KD JB2BEBrqAVIMgBgR6g6NtAY6AoTGAgmwqfk1ULU8GNkOQ/8jGRfT2SVzh+6uvuMvZvU2 IyBfEwgW0UTOK+JhcLnt0VnemRE0F/+lP9juwxhP/PHcGc5YMrCLsdwUeP8PtuP5vsSn FvFllmwGw+8ZqMbf06fDqY96YDRvmAftnk2+5XO+5j7xiUbF/2PLEV6ofBBnqYlhaxpc id0ITKdrhsAM/Cph9a41k/APjGCFXHxPXilA9kmFkaJJq+OVWxmwjlJESd/5YifouRgt Nx0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=23C+euOSgJzkF6O0iduWVYQgq1WHaZfBcycCNJNl5gM=; b=rVDEY95pZQveXq4Ci4rqeEvWpG4+Ed1nUP7m6GCQ4wZLQTGPYA5WPWS2WqFNU58qqT sKk6g91XSsCo2h1XLYltsuWi9a5jso1Ey9X1Y2j+bgPwktbywkZF7+P4E0C9ScFilG3/ xqPm7zwabFLXPYZGZEW//r4CPd6V38Hg162smrOELXtc4hIpKYreqiLFmjQDdkzeD35O DG9LV4kJTG8OIkY0bnTquAb2rrEpurJNVX7P6y/+WMhpUMO7kf49jePeHQW2o3DkH7s8 GQJAXyVaM1V9zG+yv7rnutXtzJ9LKs6AnvFoRRFDjqzHlWHmNFY3i9H+2nOgnHvlhcln nraA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=QynHfirc; 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 l23-20020a056402125700b004674aa77346si11056845edw.72.2022.11.22.02.27.01; Tue, 22 Nov 2022 02:27:02 -0800 (PST) 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=QynHfirc; 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 B1BD168B9FA; Tue, 22 Nov 2022 12:26:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4D8B568A72F for ; Tue, 22 Nov 2022 12:26:51 +0200 (EET) Received: by mail-vk1-f172.google.com with SMTP id b81so7002069vkf.1 for ; Tue, 22 Nov 2022 02:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=6Ebj49ChtCkHzcycAzWL87mzI9TIZ6A1u9ss+NjzPIY=; b=QynHfirckKy1qYsGhyqpmNhCRgrL3vOnF5Hu7strh6jCeu+a5kBSOlL+Ob+xwT5XMG 0ckknmq/d4KqnklO1DYb/2s2opuZ9CxHstlrJOoR4Vucv9dNcOjmRYn+vqWGR0Vt5w3s RLKvUxxrtCJlKK0z0u12MgsOm3oSDgwishZCGEQa3TO7AgpmE/G6/QTIFnvtQYs63pCf gm7tJ3EWsNKDadjl9uGwoI18Eh9g7J1lp7CK4VE9JOPm6JMjWdVWHRRBuyjN8g2SnnTU kODpdS/bjmMM62Df7argo8cwSCcgkNeuHrEyE+p1xhUC89xQfaZ7jfFoKwNFiqBTS1wQ TTLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6Ebj49ChtCkHzcycAzWL87mzI9TIZ6A1u9ss+NjzPIY=; b=jXbfzwJ30nheeOvDdcoB9/VzR2yNQvcRUIFY3/5BpNSSk4skWlRBS9u9VOXiHZXo7C 0CPlmE92fEh+nurWxi0fjh+HjJniAh2/jFKXUgRJtu3DkpIxlglTjjHm5osyWIGY44pc 9JuxzzURY8XOSkv0kEiKW5A4EVxyS/5PK73X7snSg775/KTqkvAcmXr++FkZUs/PtxyH JxIDxYZoZ+UcONcY5Memyns+WBdCMCG/dtsFBzqvH1wY3Wg1eaGThFBG/HUEgB1YYWST qN/fNX3UmC5cqNA9nCDvNGeRflw18HEQfXwLKQFypnUhjdUOu3pcXwRg4JDer0hrlHnT eIeA== X-Gm-Message-State: ANoB5pmTtu9qtCWGEOvFYJoObllksu8YeLjXohY0tx79tI9ke1bsFOn2 MAT7gx+7u8N98P+5W5+RJ2qRV70PLhvVBjf6wOWZSwsB X-Received: by 2002:a1f:eb41:0:b0:3b8:bbd7:8ca with SMTP id j62-20020a1feb41000000b003b8bbd708camr2147855vkh.39.1669112809610; Tue, 22 Nov 2022 02:26:49 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a05:612c:2428:b0:32a:5eaa:92e4 with HTTP; Tue, 22 Nov 2022 02:26:48 -0800 (PST) From: Paul B Mahol Date: Tue, 22 Nov 2022 11:26:48 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] avcodec/bonk: check level value to not reach invalid 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: zNV3jGM4yDye Patch attached. From 1b9204a39ea111f4fa34fe9cb4254dea2f20923d Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Tue, 22 Nov 2022 11:27:39 +0100 Subject: [PATCH] avcodec/bonk: check level value to not reach invalid values Signed-off-by: Paul B Mahol --- libavcodec/bonk.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavcodec/bonk.c b/libavcodec/bonk.c index 2b2e202428..4793bf2561 100644 --- a/libavcodec/bonk.c +++ b/libavcodec/bonk.c @@ -217,6 +217,9 @@ static int intlist_read(BonkContext *s, int *buf, int entries, int base_2_part) level += 1 << low_bits; } + if (level > 1 << 15) + return AVERROR_INVALIDDATA; + if (x >= max_x) return AVERROR_INVALIDDATA; @@ -330,7 +333,7 @@ static int bonk_decode(AVCodecContext *avctx, AVFrame *frame, skip_bits(gb, s->skip); if ((ret = intlist_read(s, s->k, s->n_taps, 0)) < 0) - return ret; + goto fail; for (int i = 0; i < s->n_taps; i++) s->k[i] *= s->quant[i]; @@ -345,7 +348,7 @@ static int bonk_decode(AVCodecContext *avctx, AVFrame *frame, predictor_init_state(s->k, state, s->n_taps); if ((ret = intlist_read(s, s->input_samples, samples_per_packet, 1)) < 0) - return ret; + goto fail; for (int i = 0; i < samples_per_packet; i++) { for (int j = 0; j < s->down_sampling - 1; j++) { @@ -390,6 +393,7 @@ static int bonk_decode(AVCodecContext *avctx, AVFrame *frame, n = get_bits_count(gb) / 8; if (n > buf_size) { +fail: s->bitstream_size = 0; s->bitstream_index = 0; return AVERROR_INVALIDDATA; -- 2.37.2