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 ESMTP id 1E8CE43751 for ; Sun, 25 Dec 2022 22:03:36 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 930D468B9B7; Mon, 26 Dec 2022 00:03:32 +0200 (EET) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6784E68B080 for ; Mon, 26 Dec 2022 00:03:25 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id AC715E0003 for ; Sun, 25 Dec 2022 22:03:24 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 25 Dec 2022 23:03:22 +0100 Message-Id: <20221225220323.20968-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/hdrdec: Check for end of input in decompress() 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 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: Timeout Fixes: 54386/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HDR_fuzzer-5053598268784640 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/hdrdec.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libavcodec/hdrdec.c b/libavcodec/hdrdec.c index 21d3e7f693..998227744b 100644 --- a/libavcodec/hdrdec.c +++ b/libavcodec/hdrdec.c @@ -58,6 +58,8 @@ static int decompress(uint8_t *scanline, int w, GetByteContext *gb, const uint8_ int rshift = 0; while (w > 0) { + if (bytestream2_get_bytes_left(gb) < 4) + return AVERROR_INVALIDDATA; scanline[0] = bytestream2_get_byte(gb); scanline[1] = bytestream2_get_byte(gb); scanline[2] = bytestream2_get_byte(gb); @@ -143,13 +145,17 @@ static int hdr_decode_frame(AVCodecContext *avctx, AVFrame *p, int i; if (width < MINELEN || width > MAXELEN) { - decompress(scanline, width, &gb, scanline); + ret = decompress(scanline, width, &gb, scanline); + if (ret < 0) + return ret; goto convert; } i = bytestream2_peek_byte(&gb); if (i != 2) { - decompress(scanline, width, &gb, scanline); + ret = decompress(scanline, width, &gb, scanline); + if (ret < 0) + return ret; goto convert; } bytestream2_skip(&gb, 1); @@ -161,7 +167,9 @@ static int hdr_decode_frame(AVCodecContext *avctx, AVFrame *p, if (scanline[1] != 2 || scanline[2] & 128) { scanline[0] = 2; scanline[3] = i; - decompress(scanline + 4, width - 1, &gb, scanline); + ret = decompress(scanline + 4, width - 1, &gb, scanline); + if (ret < 0) + return ret; goto convert; } -- 2.17.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".