From patchwork Sat Mar 16 16:32:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 12330 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 1FB0D446295 for ; Sat, 16 Mar 2019 18:34:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F37A5689CAC; Sat, 16 Mar 2019 18:34:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe08-3.mx.upcmail.net (vie01a-dmta-pe08-3.mx.upcmail.net [84.116.36.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A47A1687EBA for ; Sat, 16 Mar 2019 18:34:09 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe08.mx.upcmail.net with esmtp (Exim 4.91) (envelope-from ) id 1h5CG9-0002cR-0s for ffmpeg-devel@ffmpeg.org; Sat, 16 Mar 2019 17:34:09 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 5CFAhVl9CxLwq5CFAhXgmq; Sat, 16 Mar 2019 17:33:09 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.41.20 X-CNFS-Analysis: v=2.3 cv=WaxylHpX c=1 sm=1 tr=0 a=I1eytVlZLDX1BM2VTtTtSw==:117 a=I1eytVlZLDX1BM2VTtTtSw==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=wAZNml5c-1PtX8REAXwA:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=pHzHmUro8NiASowvMSCR:22 a=nt3jZW36AmriUCFCBwmW:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 16 Mar 2019 17:32:11 +0100 Message-Id: <20190316163211.29288-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-CMAE-Envelope: MS4wfP6vAsPhSRczbj7jKP0A3lSAbha+MUHCkc/JwjCOzXYnhIkhO75xsNIYmUwNrPMtfsJ54+PYoHejijX3NaGCMIuFak+T+zs3iur/LKcW14oER3A2FUj7 hO1V77I27NObLsqZpyxzRSgFYG72VN4SjEhLZB9VOlX6mP94PE0SpKYw Subject: [FFmpeg-devel] [PATCH] avcodec/dxtory: Check slice sizes before allocating image 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes: Timeout (26sec -> 2sec) Fixes: 13612/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DXTORY_fuzzer-5676845977042944 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/dxtory.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c index 285ca38efb..7024b315d1 100644 --- a/libavcodec/dxtory.c +++ b/libavcodec/dxtory.c @@ -272,10 +272,11 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic, setup_lru_func setup_lru, enum AVPixelFormat fmt) { - GetByteContext gb; + GetByteContext gb, gb_check; GetBitContext gb2; int nslices, slice, line = 0; uint32_t off, slice_size; + uint64_t off_check; uint8_t lru[3][8]; int ret; @@ -283,6 +284,13 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic, if (ret < 0) return ret; + off_check = off; + gb_check = gb; + for (slice = 0; slice < nslices; slice++) + off_check += bytestream2_get_le32(&gb_check); + if (off_check - avctx->discard_damaged_percentage*off_check/100 > src_size) + return AVERROR_INVALIDDATA; + avctx->pix_fmt = fmt; if ((ret = ff_get_buffer(avctx, pic, 0)) < 0) return ret;