From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 328F24EC9F for ; Wed, 14 May 2025 01:40:07 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 357FA68BB4E; Wed, 14 May 2025 04:40:03 +0300 (EEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D417B68B8BF for ; Wed, 14 May 2025 04:39:55 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 2094A43A12 for ; Wed, 14 May 2025 01:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1747186795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=rFoc8BcIoSCshY8QZVMd/E4uWRzo8uD4WRz8FX8SDoQ=; b=P4eDmUUKLJBfFEAfEEwnDTxXZgmJbgmNq3nbETLu0q87vJkjJi6Ii/Rx3q10GOmUeDfaC0 avlehZeMAJWcZkG7WHsMv5XlAIH0gJPkl79KD6P9SZNYnjp0frM+cBt6EE/nbm13aoiNGq 5bEcF6Ouv0pGHtRvWYEv8CcGCDfgiyr1x/Wb+G2aBzwmfSZqJA+uHnzRPzNk3KZb5vzUWd i0BOTSDNiS4Z/DbSK7VEj/5sbMB7yO/Ev0LeY82ngUdMT6tkrkx2TqJ9wH7ArYgwZeekSz /lwbck7WoMW2DUyCtUNqKmRN8sBee3x718r8Pol9F8FVvDSZeCfThsiNk9VxLw== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 14 May 2025 03:39:52 +0200 Message-ID: <20250514013954.2987037-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -85 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeftdehieelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdduhedmnecujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpefoihgthhgrvghlucfpihgvuggvrhhmrgihvghruceomhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtqeenucggtffrrghtthgvrhhnpeejffeufeffveevtdfhueevtdefjeetheeiteffheetgedvudduvedtffefjefhleenucffohhmrghinhepghhithhhuhgsrdgtohhmnecukfhppeeguddrieeirdeijedruddufeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeguddrieeirdeijedruddufedphhgvlhhopehlohgtrghlhhhoshhtpdhmrghilhhfrhhomhepmhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtpdhnsggprhgtphhtthhopedupdhrtghpthhtohepfhhfmhhpvghgqdguvghvvghlsehffhhmphgvghdrohhrgh X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/ffv1enc_template: Fix remaining space check 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Fixes: Assertion sc->slice_coding_mode == 0 failed at libavcodec/ffv1enc.c:1667 Fixes: 408838118/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFV1_fuzzer-6493138204295168 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/ffv1enc_template.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 64f3c420c51..aaf82159eef 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -38,19 +38,13 @@ RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc, if (bits == 0) return 0; - if (ac != AC_GOLOMB_RICE) { - if (c->bytestream_end - c->bytestream < w * 35) { + if (sc->slice_coding_mode == 1) { + av_assert0(ac != AC_GOLOMB_RICE); + if (c->bytestream_end - c->bytestream < (w * bits + 7LL)>>3) { av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n"); return AVERROR_INVALIDDATA; } - } else { - if (put_bytes_left(&sc->pb, 0) < w * 4) { - av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too large\n"); - return AVERROR_INVALIDDATA; - } - } - if (sc->slice_coding_mode == 1) { for (x = 0; x < w; x++) { int i; int v = sample[0][x]; @@ -62,6 +56,18 @@ RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc, return 0; } + if (ac != AC_GOLOMB_RICE) { + if (c->bytestream_end - c->bytestream < w * 35) { + av_log(logctx, AV_LOG_ERROR, "encoded Range Coder frame too large\n"); + return AVERROR_INVALIDDATA; + } + } else { + if (put_bytes_left(&sc->pb, 0) < w * 4) { + av_log(logctx, AV_LOG_ERROR, "encoded Golomb Rice frame too large\n"); + return AVERROR_INVALIDDATA; + } + } + for (x = 0; x < w; x++) { int diff, context; -- 2.49.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".