From patchwork Sun Sep 17 00:42:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 5169 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.36.26 with SMTP id f26csp2116435jaa; Sat, 16 Sep 2017 17:42:35 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAKsTKkE/Q35pXCdngIjBtBUpN7bQkt52gxX09LlUeifsqOeoStPVpMN0G4fMkAcLSqzAGq X-Received: by 10.28.146.68 with SMTP id u65mr5808475wmd.28.1505608955866; Sat, 16 Sep 2017 17:42:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505608955; cv=none; d=google.com; s=arc-20160816; b=FepaQ1ck9uSreRlbKcecOt71tUph6GZ0LNBJJsBbaD8J/ZDiSm3t8GTZpPdiTOd3CX tTctH8XAllqFBNsj9VXKCvwJAays54wZCSlCd05yEM8DeeIVYGt5SR5wJmIYwaqoQyJU YhLHEA0IZ9EkkTgzoEQ11Xol4PmoM0ERdczXbAn2UAozAef97XKZdz5qbQFlkiI7ryqE BGLlZtoMM6tEahMrxMc5MeTlQ+FdBu0hZdYR/g28UfP4+P1kUJIgVUILfSfIW/83aD8y ijdlP2W2GdREe2y/ipBIj1kYyrz7Sum856LrfPL3AWNCIoEdCEPehVdI9ksgG1EamHpu /SfA== 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=2BZfpeQeMcocZ7bab3oFoL8/jtNtPdAif7+bvurAxjI=; b=PgQ9hkDlzmkACSmlRsHaicR0sdsvVD2Mym0Gp3zxzVSskk5YAJiY4kMVzVFbwyxjVa lVaab50VyTE9F0VRj9tzTjFZkAMmZGtaTxfsfXfco5YDVWr+iOQVQ0S8usuu7QwgtXa1 fZ+oWyLeXm8SJOnUp0Qk7HoxnC9H87xY7/4gt6OqbTFem+L2e2KQW2r5Zv0jzuaZMvi8 inkx9GSnWjHvwuDp3E2pTH4pq545c1hnWmsnRKUtd9WX4BDj8mBrCJPxPtor7TraEzEG KYPqF6A6d0mx6BzVymSftnBcRcvmsPQpYO8nEQpmJeaqWvSLiM7DAiqXvnNpNJLzJ7gG 1wfQ== 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 t141si3388308wmd.54.2017.09.16.17.42.35; Sat, 16 Sep 2017 17:42:35 -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 2E05B6899F5; Sun, 17 Sep 2017 03:42:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-3.mx.upcmail.net (vie01a-qmta-pe02-3.mx.upcmail.net [62.179.121.183]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7DF30689988 for ; Sun, 17 Sep 2017 03:42:19 +0300 (EEST) Received: from [172.31.218.52] (helo=vie01a-dmta-pe08-1.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dtNfG-0003US-RL for ffmpeg-devel@ffmpeg.org; Sun, 17 Sep 2017 02:42:26 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe08.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dtNfB-0002qy-8C for ffmpeg-devel@ffmpeg.org; Sun, 17 Sep 2017 02:42:21 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id AQiC1w01E0S5wYM01QiDQW; Sun, 17 Sep 2017 02:42:14 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 17 Sep 2017 02:42:10 +0200 Message-Id: <20170917004211.12545-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.14.1 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/wmv2dec: Check end of bitstream in parse_mb_skip() and ff_wmv2_decode_mb() 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: 3200/clusterfuzz-testcase-5750022136135680 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/wmv2dec.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c index 20dbee5703..62291d4163 100644 --- a/libavcodec/wmv2dec.c +++ b/libavcodec/wmv2dec.c @@ -30,7 +30,7 @@ #include "wmv2.h" -static void parse_mb_skip(Wmv2Context *w) +static int parse_mb_skip(Wmv2Context *w) { int mb_x, mb_y; MpegEncContext *const s = &w->s; @@ -45,6 +45,8 @@ static void parse_mb_skip(Wmv2Context *w) MB_TYPE_16x16 | MB_TYPE_L0; break; case SKIP_TYPE_MPEG: + if (get_bits_left(&s->gb) < s->mb_height * s->mb_width) + return AVERROR_INVALIDDATA; for (mb_y = 0; mb_y < s->mb_height; mb_y++) for (mb_x = 0; mb_x < s->mb_width; mb_x++) mb_type[mb_y * s->mb_stride + mb_x] = @@ -52,6 +54,8 @@ static void parse_mb_skip(Wmv2Context *w) break; case SKIP_TYPE_ROW: for (mb_y = 0; mb_y < s->mb_height; mb_y++) { + if (get_bits_left(&s->gb) < 1) + return AVERROR_INVALIDDATA; if (get_bits1(&s->gb)) { for (mb_x = 0; mb_x < s->mb_width; mb_x++) mb_type[mb_y * s->mb_stride + mb_x] = @@ -65,6 +69,8 @@ static void parse_mb_skip(Wmv2Context *w) break; case SKIP_TYPE_COL: for (mb_x = 0; mb_x < s->mb_width; mb_x++) { + if (get_bits_left(&s->gb) < 1) + return AVERROR_INVALIDDATA; if (get_bits1(&s->gb)) { for (mb_y = 0; mb_y < s->mb_height; mb_y++) mb_type[mb_y * s->mb_stride + mb_x] = @@ -77,6 +83,7 @@ static void parse_mb_skip(Wmv2Context *w) } break; } + return 0; } static int decode_ext_header(Wmv2Context *w) @@ -170,9 +177,12 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) } } else { int cbp_index; + int ret; w->j_type = 0; - parse_mb_skip(w); + ret = parse_mb_skip(w); + if (ret < 0) + return ret; cbp_index = decode012(&s->gb); w->cbp_table_index = wmv2_get_cbp_table_index(s, cbp_index); @@ -345,6 +355,12 @@ int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) if (w->j_type) return 0; + if (get_bits_left(&s->gb) < 0) { + av_log(s->avctx, AV_LOG_ERROR, + "Insufficient bits left at %d %d\n", s->mb_x, s->mb_y); + return AVERROR_INVALIDDATA; + } + if (s->pict_type == AV_PICTURE_TYPE_P) { if (IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])) { /* skip mb */