From patchwork Fri Oct 13 01:06:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 5546 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp133058jah; Thu, 12 Oct 2017 18:07:14 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDDpPwqu1UPdddXq9RV7YC33OPVPyoaJPZIDZnFIvF3yYLRaiQpjf+Pxhykbs+Ap8JwXUdr X-Received: by 10.223.141.139 with SMTP id o11mr3305127wrb.20.1507856834709; Thu, 12 Oct 2017 18:07:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507856834; cv=none; d=google.com; s=arc-20160816; b=zQQNZDHP7N9eIhM4rAZcTTEri4BLAh5pmT0JjXYdf79oOLrwosoBoHKe90+gK+Yr4x TvkWO7e1I7t1La1rQCmaYSfVBKv70onAOkZaDFeb75p5QF38iS/5Fz8nI+j7akMbrXph Dh/fFM1LVVv3Xm56GB1eYXuboW1mSlJWpCeSLDxmsZ4pUJZtoK29EEaZSpMnlFPlbp1a Dd1qqDRYgYyba9EfgKs44hyZuJUNc+xgIvT7fRJcc8pemMzyCz7Cm8H1cB01zv7KdVc0 QFeNJso/ZJ5b0//kjGIuNGB0gKvylOHIASnf1WWfqyHZvFHznM1wkYOTUvlCTbZD05lK rCVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=PGB4nlJYh2+gHAy48RPgU9v14/7s8O2HfwdhL7x0Qxs=; b=o4vgcDfMtxdJxXgIKFCv/NLb6kOA1PkBPoKytXTBza86mduOYfCTtZeQxGnNe77Q1Z k4TK+LGWmYzlk7aUmA5PnA3r+SMVCfF6LeJEPZxTd9GKsH90bM3VfeB5tkjr2TcmxXaP L4YG1Y4SsiUndt7rmrFjiKN/Y1lKU/55xXwyZHXv99cpYg9IanyNLKM5sL/LC3aNBUkl nY8RKHnOTBQu22+mqRt2x5xih30MHk0tYrOwaO1rGACpDZ7GVsQsA3hTtMItMdFtD5Q6 yFlky8AlNh2DlPPI1fOuRJANkiohOJqLYnypdegKI28vZ8UraKIXe4cQopmluuVf9AWz hhNw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 11si47205wmx.90.2017.10.12.18.07.13; Thu, 12 Oct 2017 18:07:14 -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 08B4068A056; Fri, 13 Oct 2017 04:07:09 +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 80508689FA2 for ; Fri, 13 Oct 2017 04:07:02 +0300 (EEST) Received: from [172.31.218.35] (helo=vie01a-dmta-pe02-2.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1e2oRN-0005w2-AK for ffmpeg-devel@ffmpeg.org; Fri, 13 Oct 2017 03:07:05 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1e2oRH-0003Xz-8G for ffmpeg-devel@ffmpeg.org; Fri, 13 Oct 2017 03:06:59 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id Lp6u1w01H0S5wYM01p6vUr; Fri, 13 Oct 2017 03:06:56 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 13 Oct 2017 03:06:53 +0200 Message-Id: <20171013010654.16525-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.14.2 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/pafvideo: Check for bitstream end in decode_0() 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: Timeout Fixes: 3529/clusterfuzz-testcase-5057068371279872 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/pafvideo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavcodec/pafvideo.c b/libavcodec/pafvideo.c index 91bfe16376..6980ae1b35 100644 --- a/libavcodec/pafvideo.c +++ b/libavcodec/pafvideo.c @@ -181,6 +181,8 @@ static int decode_0(PAFVideoDecContext *c, uint8_t *pkt, uint8_t code) dend = c->frame[page] + c->frame_size; offset = (x & 0x7F) * 2; j = bytestream2_get_le16(&c->gb) + offset; + if (bytestream2_get_bytes_left(&c->gb) < (j - offset) * 16) + return AVERROR_INVALIDDATA; do { offset++; if (dst + 3 * c->width + 4 > dend) @@ -198,7 +200,8 @@ static int decode_0(PAFVideoDecContext *c, uint8_t *pkt, uint8_t code) do { set_src_position(c, &src, &send); if ((src + 3 * c->width + 4 > send) || - (dst + 3 * c->width + 4 > dend)) + (dst + 3 * c->width + 4 > dend) || + bytestream2_get_bytes_left(&c->gb) < 4) return AVERROR_INVALIDDATA; copy_block4(dst, src, c->width, c->width, 4); i++;