From patchwork Thu Oct 15 15:52:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 22969 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3FC404497F9 for ; Thu, 15 Oct 2020 19:01:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1455D68B9C8; Thu, 15 Oct 2020 19:01:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-3.mx.upcmail.net (vie01a-dmta-pe05-3.mx.upcmail.net [84.116.36.13]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B550868B944 for ; Thu, 15 Oct 2020 19:01:49 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1kT5Ze-0000Ht-0E for ffmpeg-devel@ffmpeg.org; Thu, 15 Oct 2020 17:53:50 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id T5YfkX4esIr7GT5Yfkd58P; Thu, 15 Oct 2020 17:52:49 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=QN4WuTDL c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=pu1buFpvyLDWrnlBZSgA:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=jd6J4Gguk5HxikPWLKER:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 15 Oct 2020 17:52:48 +0200 Message-Id: <20201015155248.30957-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfBe1d+LxEY3m25V74+60riy4kG/yuSYpGq81+Pi3EbiuFFR3TxnrxwDUwKPgmoMRe2+oIivja0ZBcb3dXSpPDqKmAeyJJ+zz8NDT9rd/DKzBiYwIPW8K /WNlkP3i+jj0I6bdhtMZpe4zIb8oe7fZ2FGBESPi9SVC0Vw2OkWF9BdK Subject: [FFmpeg-devel] [PATCH] avcodec/cri: Check for end of image in unpack_10bit() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Fixes: out of array write Fixes: 26242/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CRI_fuzzer-5161495882891264 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/cri.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libavcodec/cri.c b/libavcodec/cri.c index 3aad76a008..dafbc1f1be 100644 --- a/libavcodec/cri.c +++ b/libavcodec/cri.c @@ -87,54 +87,72 @@ static void unpack_10bit(GetByteContext *gb, uint16_t *dst, int shift, dst[pos] = (((a0 >> 1) & 0xE00) | (a0 & 0x1FF)) << shift; pos++; if (pos >= w) { + if (count == 1) + break; dst += stride; pos = 0; } dst[pos] = (((a0 >> 13) & 0x3F) | ((a0 >> 14) & 0xFC0)) << shift; pos++; if (pos >= w) { + if (count == 2) + break; dst += stride; pos = 0; } dst[pos] = (((a0 >> 26) & 7) | ((a1 & 0x1FF) << 3)) << shift; pos++; if (pos >= w) { + if (count == 3) + break; dst += stride; pos = 0; } dst[pos] = (((a1 >> 10) & 0x1FF) | ((a1 >> 11) & 0xE00)) << shift; pos++; if (pos >= w) { + if (count == 4) + break; dst += stride; pos = 0; } dst[pos] = (((a1 >> 23) & 0x3F) | ((a2 & 0x3F) << 6)) << shift; pos++; if (pos >= w) { + if (count == 5) + break; dst += stride; pos = 0; } dst[pos] = (((a2 >> 7) & 0xFF8) | ((a2 >> 6) & 7)) << shift; pos++; if (pos >= w) { + if (count == 6) + break; dst += stride; pos = 0; } dst[pos] = (((a3 & 7) << 9) | ((a2 >> 20) & 0x1FF)) << shift; pos++; if (pos >= w) { + if (count == 7) + break; dst += stride; pos = 0; } dst[pos] = (((a3 >> 4) & 0xFC0) | ((a3 >> 3) & 0x3F)) << shift; pos++; if (pos >= w) { + if (count == 8) + break; dst += stride; pos = 0; } dst[pos] = (((a3 >> 16) & 7) | ((a3 >> 17) & 0xFF8)) << shift; pos++; if (pos >= w) { + if (count == 9) + break; dst += stride; pos = 0; }