From patchwork Tue Jan 24 23:42:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 40103 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp743797pzj; Tue, 24 Jan 2023 15:43:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXsQNv8Lc6pLGifMA4h0oWYRgmFvNm9+h5yTIXqk1YizU+8F8GS8rBOSxus1E5IFPyR60pEQ X-Received: by 2002:a17:907:8b8a:b0:82e:a57b:cc9b with SMTP id tb10-20020a1709078b8a00b0082ea57bcc9bmr50840548ejc.24.1674603789075; Tue, 24 Jan 2023 15:43:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674603789; cv=none; d=google.com; s=arc-20160816; b=nSPE3eZ+XorIWat9ut4pE/8ho2DNyvOj0bUMQBgcBFVkTj21SAK6kfJVAOo774uU81 4zPYS6tLYQhMDNRRIr5Re12w/CLbY2vlv3AAQmsfobfj+i4m01tmd7ZfQ/CQBPbRNqE6 i3it/svj94x6vfBQAL+gafMwln2QVUPa96UrXKe/BRncphxYh+Ff9l3x3WlNvC4f0L4N N2kEK/xay37GYVmEirKbYbvAxLFdTjk2uNbr5uo8gjJerV9OFeRSvQu77aUT2Qc/y3mW 5/AewwnuByKBC0Ls2sipQWqoM6ryMBlFy5hj5H1xXrRXMrlPLys8HA9GgCvhYW0yzjpN FXew== 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=8QvJFtFijBKRoFYHsFvyyYLWH2hLlV/1xaIIEJue7qs=; b=D942aC2tEOL7KQTHy08eO5coZxN98M/rWu/HPaBqy1QK/Fh5SK4BDUp3I6E+8sD/UB jN5WcLAL7ksE5+NIk/e2ty8uz/4qYLp04dvYJwhW+sBNHrt+2khaJnUro4bRerwXNb7X s/Sy7bsfCLFh/mcGrA9hVHA/+el2rJ2G781x4hyyBcMJSCBrpYMCvBpvd5KaYj4h+Xf9 NCfeqcv5zL33zXC933jt8eAFseMsMFUvOCKR2VJxoHobxc3ZpbNHIp1c1lYnpYUTlfXc 0NRRfx4nbpLukHrAkHBWV+ZWyOKNPQ1Kooq3orz+GYAtn6hVvJbMhf4pUL3u4DroGmr1 EOKQ== 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 25-20020a170906225900b00877a6da8f57si3867458ejr.747.2023.01.24.15.43.08; Tue, 24 Jan 2023 15:43:09 -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 10FBB68BE4F; Wed, 25 Jan 2023 01:43:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BFE8368BD2B for ; Wed, 25 Jan 2023 01:42:56 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id CB975240004 for ; Tue, 24 Jan 2023 23:42:55 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 25 Jan 2023 00:42:53 +0100 Message-Id: <20230124234254.30008-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/g2meet: Replace fake allocation avoidance for framebuf 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: ST6pgibiZAxF framebuf is only allocated when the new width/height are larger than the old but nothing sets the old so its always allocated. Use av_fast_mallocz() instead. Fixes: Timeout Fixes: 55094/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_G2M_fuzzer-5116909932904448 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/g2meet.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c index 761fd22fc3..7363c2212d 100644 --- a/libavcodec/g2meet.c +++ b/libavcodec/g2meet.c @@ -145,7 +145,8 @@ typedef struct G2MContext { int got_header; uint8_t *framebuf; - int framebuf_stride, old_width, old_height; + int framebuf_stride; + unsigned int framebuf_allocated; uint8_t *synth_tile, *jpeg_tile, *epic_buf, *epic_buf_base; int tile_stride, epic_buf_stride, old_tile_w, old_tile_h; @@ -1160,14 +1161,13 @@ static int g2m_init_buffers(G2MContext *c) { int aligned_height; - if (!c->framebuf || c->old_width < c->width || c->old_height < c->height) { - c->framebuf_stride = FFALIGN(c->width + 15, 16) * 3; - aligned_height = c->height + 15; - av_free(c->framebuf); - c->framebuf = av_calloc(c->framebuf_stride, aligned_height); - if (!c->framebuf) - return AVERROR(ENOMEM); - } + c->framebuf_stride = FFALIGN(c->width + 15, 16) * 3; + aligned_height = c->height + 15; + + av_fast_mallocz(&c->framebuf, &c->framebuf_allocated, c->framebuf_stride * aligned_height); + if (!c->framebuf) + return AVERROR(ENOMEM); + if (!c->synth_tile || !c->jpeg_tile || (c->compression == 2 && !c->epic_buf_base) || c->old_tile_w < c->tile_width || @@ -1617,6 +1617,7 @@ static av_cold int g2m_decode_end(AVCodecContext *avctx) av_freep(&c->jpeg_tile); av_freep(&c->cursor); av_freep(&c->framebuf); + c->framebuf_allocated = 0; return 0; }