From patchwork Fri Nov 18 21:09:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 39333 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp612037pzb; Fri, 18 Nov 2022 13:10:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf7vlIgdOgsDVHJMm8rbczpGX38evzLuMRpqdfrHBYrRF8pywUMCID3k/mhRxtToTlDfOxGc X-Received: by 2002:a05:6402:114c:b0:457:35d4:ac66 with SMTP id g12-20020a056402114c00b0045735d4ac66mr7616114edw.415.1668805801211; Fri, 18 Nov 2022 13:10:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668805801; cv=none; d=google.com; s=arc-20160816; b=sRtfBrO6pOoGeXvoKDFZcxte5iIx79Kv1YKk9UQW+DZ2OiwZ1yx7zF02Ffk82mgYqU lB6FPCwPqN4ybz1BUkQJ7+3EII67GvxbsK8UPwhpF8c89hwmPAox/E7aHMKOGbNrwgND Mr6tmBQKKcx4naKJj8IbYL7wvQbfqZ+EA1mzSJB9O6gJ2BW1Ufiiw/XdwNqloh0hWCgq oD1M4JP3d92TV1K+MGF9ECWEGU6eRDLwHV+h84lTaD8Y8xzZT+vCqC6I6oUckZZgJK+m cwoTr9QDIGTjP8jN0o3+UwxEo5sXrKxlQ3CeBvqoB0qq5oV4XmKGENlqYceETG6clDs9 xUHA== 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=3kvYWkGScOvK9ThUW4m3/SVHgrsgQ3YhbxOujjPP4m0=; b=H7Gtc5EyDelUabiU3Hi0bbZ3y5jAM2geZXnXMoJ8BDMK/Dpcgl7ok54qwjLdBIXql8 4zI5VJYoa0x8VC7w8w56Mei38s4XUWEvQ+d9O4+DrrvlfNez+als/r9d/NuDMEf2JwEG Tq9rl+geHQySdwDnozAn9Qo3LeO1j44TA7PBIR0cMUF0HS3FtWR5t2XtVgLd8jJVLDBq OOauPbRSLtdJtRGLS2NlTjvRGBHjw+ZL4yakk0kIL7LvXa82jMnSjYPfH8xRc58L9cke NtE/r1BFMFr0tYclVXf+hPUTfJd/tGoBz0JLJci9b8xZpypjqKcV2egUdANSqmYHvzMW WMIw== 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 rl24-20020a170907217800b00770d9e664f8si3165464ejb.152.2022.11.18.13.10.00; Fri, 18 Nov 2022 13:10:01 -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; 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 EFD9E68BB52; Fri, 18 Nov 2022 23:09:32 +0200 (EET) 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 C352D68B7BA for ; Fri, 18 Nov 2022 23:09:24 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id E82C4FF80B for ; Fri, 18 Nov 2022 21:09:23 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 18 Nov 2022 22:09:18 +0100 Message-Id: <20221118210918.3169-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221118210918.3169-1-michael@niedermayer.cc> References: <20221118210918.3169-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/vqcdec: Check for end of input in decode_vectors() 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: 6OAqXzM55btu Fixes: Timeout Fixes: 52695/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VQC_fuzzer-4882310386548736 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/vqcdec.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libavcodec/vqcdec.c b/libavcodec/vqcdec.c index 5d1a03158c..18cd99462e 100644 --- a/libavcodec/vqcdec.c +++ b/libavcodec/vqcdec.c @@ -137,7 +137,7 @@ static void seed_codebooks(VqcContext * s, const int * seed) } } -static void decode_vectors(VqcContext * s, const uint8_t * buf, int size, int width, int height) +static int decode_vectors(VqcContext * s, const uint8_t * buf, int size, int width, int height) { GetBitContext gb; uint8_t * vectors = s->vectors; @@ -155,9 +155,11 @@ static void decode_vectors(VqcContext * s, const uint8_t * buf, int size, int wi *dst++ = get_bits(&gb, 8); while (show_bits(&gb, 2) != 2) { - if (dst >= vectors_end - 1) - return; + return 0; + + if (get_bits_left(&gb) < 4) + return AVERROR_INVALIDDATA; if (!show_bits(&gb, 4)) { *dst++ = 0; @@ -182,6 +184,8 @@ static void decode_vectors(VqcContext * s, const uint8_t * buf, int size, int wi skip_bits(&gb, 2); vectors += 32; } + + return 0; } static void load_coeffs(VqcContext * s, const uint8_t * v, int width, int coeff_width) @@ -392,7 +396,9 @@ static int vqc_decode_frame(AVCodecContext *avctx, AVFrame * rframe, avpriv_request_sample(avctx, "gamma=0x%x, contrast=0x%x\n", gamma, contrast); seed_codebooks(s, seed); - decode_vectors(s, buf + 7, avpkt->size - 7, avctx->width, avctx->height); + ret = decode_vectors(s, buf + 7, avpkt->size - 7, avctx->width, avctx->height); + if (ret < 0) + return ret; decode_frame(s, avctx->width, avctx->height); if ((ret = av_frame_ref(rframe, s->frame)) < 0)