From patchwork Mon May 1 22:54:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 3537 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp1604735vsd; Mon, 1 May 2017 15:54:54 -0700 (PDT) X-Received: by 10.28.125.137 with SMTP id y131mr2119347wmc.141.1493679294420; Mon, 01 May 2017 15:54:54 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 32si13428142wrd.231.2017.05.01.15.54.53; Mon, 01 May 2017 15:54:54 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 38B3E68921C; Tue, 2 May 2017 01:54:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-1.mx.upcmail.net (vie01a-qmta-pe02-1.mx.upcmail.net [62.179.121.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B88566882AE for ; Tue, 2 May 2017 01:54:40 +0300 (EEST) Received: from [172.31.218.39] (helo=vie01a-dmta-pe03-3.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1d5KDL-0000Wn-U5 for ffmpeg-devel@ffmpeg.org; Tue, 02 May 2017 00:54:43 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe03.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1d5KDF-0004ap-Rd for ffmpeg-devel@ffmpeg.org; Tue, 02 May 2017 00:54:37 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id FAub1v00i0S5wYM01AucK9; Tue, 02 May 2017 00:54:36 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 2 May 2017 00:54:34 +0200 Message-Id: <20170501225434.4834-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] avcodec/flicvideo: Check for chunk overread 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 integer overflow Fixes: 1292/clusterfuzz-testcase-minimized-5795512143839232 Signed-off-by: Michael Niedermayer --- libavcodec/flicvideo.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libavcodec/flicvideo.c b/libavcodec/flicvideo.c index b1b7b5a42f..7f9b871dc7 100644 --- a/libavcodec/flicvideo.c +++ b/libavcodec/flicvideo.c @@ -444,8 +444,12 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx, break; } - if (stream_ptr_after_chunk - bytestream2_tell(&g2) > 0) + if (stream_ptr_after_chunk - bytestream2_tell(&g2) >= 0) { bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2)); + } else { + av_log(avctx, AV_LOG_ERROR, "Chunk overread\n"); + break; + } frame_size -= chunk_size; num_chunks--; @@ -742,6 +746,13 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, break; } + if (stream_ptr_after_chunk - bytestream2_tell(&g2) >= 0) { + bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2)); + } else { + av_log(avctx, AV_LOG_ERROR, "Chunk overread\n"); + break; + } + frame_size -= chunk_size; num_chunks--; } @@ -1016,6 +1027,13 @@ static int flic_decode_frame_24BPP(AVCodecContext *avctx, break; } + if (stream_ptr_after_chunk - bytestream2_tell(&g2) >= 0) { + bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2)); + } else { + av_log(avctx, AV_LOG_ERROR, "Chunk overread\n"); + break; + } + frame_size -= chunk_size; num_chunks--; }