From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 66BA04C326 for ; Thu, 31 Jul 2025 22:48:50 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 3AFD868CF6F; Fri, 1 Aug 2025 01:48:42 +0300 (EEST) Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id C37AA687A9F for ; Fri, 1 Aug 2025 01:48:34 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id E58AD42E77; Thu, 31 Jul 2025 22:48:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1754002114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zJ1S52kzxKFTf0hj/bgA7ZoBdl0UuxfKV1HzhyThmMc=; b=LytOvkM7wyr7K/2JukCOePFsmSwzqVRLbAYUhfWhNbY7QeyXAAGB3gDEn7p+j1V7e18/CB qIkywgIlPsFocslqOgzhCpqfcEFG4LHGuYsELQv2hI+8weob5LgfU5E6E7kS7+ClIBCLAX Q7eDj/t0D1CPo1R/yGLka9s42KlojkXkXYO2hsVJbW6Kk2TuP7X/Mbht1GTWZvpPXLnVzA oYcUPqySt71QJe96c8W7e0YXBNFkykJLpMnl/DgMeHby7Z05mwfs8hOBrcJMaOEVQZxM39 77gd5b265/IVzXklMzdl1WtkCaiR3y6n5oaZN8dJAz5Shx8S8wpDHgvzA6wIaA== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 1 Aug 2025 00:48:32 +0200 Message-ID: <20250731224832.2546237-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -85 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddutddvtdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdduhedmnecujfgurhephffvvefufffkofgggfestdekredtredttdenucfhrhhomhepofhitghhrggvlhcupfhivgguvghrmhgrhigvrhcuoehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgeqnecuggftrfgrthhtvghrnhepvefggfekleektefhveeggefghfeujeeljedugedvffekvdegkeelvdfftdfhvdfgnecuffhomhgrihhnpehgihhthhhusgdrtghomhenucfkphepgedurdeiiedrieehrddujeeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepgedurdeiiedrieehrddujeeipdhhvghloheplhhotggrlhhhohhsthdpmhgrihhlfhhrohhmpehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgdpnhgspghrtghpthhtohepvddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhgpdhrtghpthhtohepmhgrnhhuvghlrdhlrghushhssehgmhgrihhlrdgtohhm X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH] avcodec/sanm: Checks related to negative left/top 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 Cc: Manuel Lauss 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: 423673969/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SANM_fuzzer-5466731806261248 Fixes: out of array access CC: Manuel Lauss Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/sanm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index 617b977ab70..d345f588463 100644 --- a/libavcodec/sanm.c +++ b/libavcodec/sanm.c @@ -1654,7 +1654,7 @@ static int process_frame_obj(SANMVideoContext *ctx, GetByteContext *gb) bytestream2_skip(gb, 2); parm2 = bytestream2_get_le16u(gb); - if (w < 1 || h < 1 || w > 800 || h > 600 || left > 800 || top > 600) { + if (w < 1 || h < 1 || w > 800 || h > 600 || left > 800 || top > 600 || left + w <= 0 || top + h <= 0) { av_log(ctx->avctx, AV_LOG_WARNING, "ignoring invalid fobj dimensions: c%d %d %d @ %d %d\n", codec, w, h, left, top); @@ -1715,7 +1715,7 @@ static int process_frame_obj(SANMVideoContext *ctx, GetByteContext *gb) } } } else { - if (((left + w > ctx->width) || (top + h > ctx->height)) && fsc) { + if (((left + w > ctx->width) || (top + h > ctx->height)) && (fsc || codec == 20)) { /* correct unexpected overly large frames: this happens * for instance with The Dig's sq1.san video: it has a few * (all black) 640x480 frames halfway in, while the rest is @@ -1775,11 +1775,11 @@ static int process_frame_obj(SANMVideoContext *ctx, GetByteContext *gb) if ((w == ctx->width) && (h == ctx->height)) { memcpy(ctx->fbuf, ctx->frm0, ctx->fbuf_size); } else { - uint8_t *dst = (uint8_t *)ctx->fbuf + left + top * ctx->pitch; const uint8_t *src = (uint8_t *)ctx->frm0; const int cw = FFMIN(w, ctx->width - left); const int ch = FFMIN(h, ctx->height - top); if ((cw > 0) && (ch > 0) && (left >= 0) && (top >= 0)) { + uint8_t *dst = (uint8_t *)ctx->fbuf + left + top * ctx->pitch; for (int i = 0; i < ch; i++) { memcpy(dst, src, cw); dst += ctx->pitch; -- 2.50.1 _______________________________________________ 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".