From patchwork Thu Aug 8 23:23:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 14344 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 59262447A60 for ; Fri, 9 Aug 2019 02:25:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 48B4768A9A0; Fri, 9 Aug 2019 02:25:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe07-3.mx.upcmail.net (vie01a-dmta-pe07-3.mx.upcmail.net [84.116.36.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A1EB76802C4 for ; Fri, 9 Aug 2019 02:25:33 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe07.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1hvrmn-0002sK-3R for ffmpeg-devel@ffmpeg.org; Fri, 09 Aug 2019 01:25:33 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id vrlnh0dKywlysvrlnhVt1r; Fri, 09 Aug 2019 01:24:32 +0200 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=E5OzWpVl 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=IHpXlaMCCFbF4JxSYzEA:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=jd6J4Gguk5HxikPWLKER:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 9 Aug 2019 01:23:46 +0200 Message-Id: <20190808232350.16076-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 X-CMAE-Envelope: MS4wfHxKPD6WEkS1Z5ph0tIcYjwUsTd3zhpx3cnZUGdJ3fe0mfL0RZgdxEBjPibqa1jkQxb+U8JNPC3Fw6TAKOK/kyQMFvotVDV02jVng9RS58+gg31vf0Kx 5na7Ou/qiQmx/kFzdxs2HOfGYZZzVmVK3/VWQ6dhFzbuDtRwxviGM09n Subject: [FFmpeg-devel] [PATCH 1/5] avcodec/tiff: Enforce increasing offsets 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" This may break some valid tiff files, it appears the specification does not require the offsets to be increasing. They increase in the 2 test files i have though except the last offset which is 0 (an end marker) and for which a special case is added to avoid asking for a sample for that end marker. See: [FFmpeg-devel] [PATCH 2/2] avcodec/tiff: Detect infinite retry loop for an alternative implementation Fixes: Timeout (Infinite -> Finite) Fixes: 15706/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-5114674904825856 This variant was requested by paul on IRC Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/tiff.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index c520d7df83..1f1a1a3698 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -1399,7 +1399,7 @@ static int decode_frame(AVCodecContext *avctx, TiffContext *const s = avctx->priv_data; AVFrame *const p = data; ThreadFrame frame = { .f = data }; - unsigned off; + unsigned off, last_off; int le, ret, plane, planes; int i, j, entries, stride; unsigned soff, ssize; @@ -1454,6 +1454,7 @@ again: /** whether we should process this multi-page IFD's next page */ retry_for_page = s->get_page && s->cur_page + 1 < s->get_page; // get_page is 1-indexed + last_off = off; if (retry_for_page) { // set offset to the next IFD off = ff_tget_long(&s->gb, le); @@ -1463,6 +1464,14 @@ again: } if (retry_for_subifd || retry_for_page) { + if (!off) { + av_log(avctx, AV_LOG_ERROR, "Requested entry not found\n"); + return AVERROR_INVALIDDATA; + } + if (off <= last_off) { + avpriv_request_sample(s->avctx, "non increasing IFD offset\n"); + return AVERROR_INVALIDDATA; + } if (off >= UINT_MAX - 14 || avpkt->size < off + 14) { av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n"); return AVERROR_INVALIDDATA;