From patchwork Tue Mar 20 01:06:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 8051 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp3291538jad; Mon, 19 Mar 2018 18:07:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELtqzaOIPK4s2Ge00aUTkT1pgmc69PasDOspx+YdEJp3WMzIsIIGgPRMkhyf8JK2BXm5eAR1 X-Received: by 10.223.159.79 with SMTP id f15mr11686090wrg.115.1521508032172; Mon, 19 Mar 2018 18:07:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521508032; cv=none; d=google.com; s=arc-20160816; b=JDNQQNd+p0pcD/1iRa1cNT8FF+zfb6PhUFlAnZjOagGecL6vSHIAyy7Vv70PcS+xS1 aidwNqwCfSVsuOQd3oPuXK0+sjfQjeAKyeLCgE+GrOxY6HnmfQLFmUQ8a06v2RvMgJVV JbiKGovFlB3HdzQQbD5lES8QDFdxFgN6xSnhvk4zU0YFWtdnpqlmV5Rw0nrCWF66CDIl 2uO8QE4kvtqvE0WfzF+CIyEdd2+yIvj0p/ptSg25GeMG8EnOtsKFzEYWb8h8mjcA3sWq hxNKU/TLJvC8fiHHl4bE/sLHQpQ8Fvjud6TQn56C6WIMCKVIXQnH9QURvHQYXTqOQ0Sn f0Zg== 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=qt3xtPKWEPUnlY8kYVZVt1RTqJCCQ0cyhfcH8dEZLgk=; b=LhCZSuhRV+xgPdiua6d2OqkVtXNpRQ4PzK5cbBbUuyHB+heXHMAWv/V1TjAQbKNjmB 3UvVmCn7KbvkH11PkwjBXDDdGTWwYd2yBf4idTjSQrXfu2vssVVIPvBzH4WXLARuLBiM TC1xU9/3WtDifasV/bh9H0njdNSzr3StISx6bFo8eTL2wt+2fnqdfRDcjBflXQCWxbsR 5nHa/0L8vkMSzxwFw9tQXwIQd6KTBDl0jhP/K1jqHPoI/y3AN7x5DEghu6gqMxN0EN66 1hAxE0kyR+rLZ6kJ6JrkFSfJmdbNa2mmp3NcAwcdAiXgL0Yi83YBKlNLgULEw1xrHDRK bzew== 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 u2si327432wmd.105.2018.03.19.18.07.10; Mon, 19 Mar 2018 18:07:12 -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 1E9B0689F3A; Tue, 20 Mar 2018 03:06:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-2.mx.upcmail.net (vie01a-qmta-pe02-2.mx.upcmail.net [62.179.121.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3EE9F680945 for ; Tue, 20 Mar 2018 03:06:49 +0200 (EET) Received: from [172.31.218.34] (helo=vie01a-dmta-pe02-1.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1ey5jy-00074w-Ui for ffmpeg-devel@ffmpeg.org; Tue, 20 Mar 2018 02:07:02 +0100 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 1ey5js-0003eJ-Oq for ffmpeg-devel@ffmpeg.org; Tue, 20 Mar 2018 02:06:56 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id Q16o1x00X0S5wYM0116pNF; Tue, 20 Mar 2018 02:06:49 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 20 Mar 2018 02:06:27 +0100 Message-Id: <20180320010627.7766-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.16.2 Subject: [FFmpeg-devel] [PATCH] avformat/mov: Check STSC and remove invalid entries 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 assertion failure Fixes: crbug 822547, crbug 822666 and crbug 823009 Affects: aark15sd_9A62E2FA.mp4 Found-by: ClusterFuzz Reviewed-by: Matt Wolenetz Signed-off-by: Michael Niedermayer --- libavformat/mov.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 232e59887e..075e833bad 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2655,6 +2655,21 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom) } sc->stsc_count = i; + for (i = sc->stsc_count - 1; i < UINT_MAX; i--) { + if ((i+1 < sc->stsc_count && sc->stsc_data[i].first >= sc->stsc_data[i+1].first) || + (i > 0 && sc->stsc_data[i].first <= sc->stsc_data[i-1].first) || + sc->stsc_data[i].first < 1 || + sc->stsc_data[i].count < 1 || + sc->stsc_data[i].id < 1) { + av_log(c->fc, AV_LOG_WARNING, "STSC entry %d is invalid (first=%d count=%d id=%d)\n", i, sc->stsc_data[i].first, sc->stsc_data[i].count, sc->stsc_data[i].id); + if (i+1 >= sc->stsc_count || sc->stsc_data[i+1].first < 2) + return AVERROR_INVALIDDATA; + // We replace this entry by the next valid + sc->stsc_data[i].first = sc->stsc_data[i+1].first - 1; + sc->stsc_data[i].count = sc->stsc_data[i+1].count; + sc->stsc_data[i].id = sc->stsc_data[i+1].id; + } + } if (pb->eof_reached) { av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted STSC atom\n"); @@ -4144,6 +4159,11 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) st->index); return 0; } + if (sc->stsc_count && sc->stsc_data[ sc->stsc_count - 1 ].first > sc->chunk_count) { + av_log(c->fc, AV_LOG_ERROR, "stream %d, contradictionary STSC and STCO\n", + st->index); + return AVERROR_INVALIDDATA; + } fix_timescale(c, sc);