From patchwork Tue Feb 5 00:30:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chcunningham@chromium.org X-Patchwork-Id: 11971 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 7AF93441BBE for ; Tue, 5 Feb 2019 02:31:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 604EA68ABCE; Tue, 5 Feb 2019 02:31:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 150BB68ABB1 for ; Tue, 5 Feb 2019 02:31:09 +0200 (EET) Received: by mail-pg1-f174.google.com with SMTP id d72so666199pga.9 for ; Mon, 04 Feb 2019 16:31:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+/ynut0iJL/DEdla9rraSr6b+opihwye7oBaNpDLvJo=; b=NXpE4ZjP+m8O5meNQ2RVIBxr0AubyLzCBpDbql+Tktam6+rB1KhCYCltdX6Vhi56mB /Ta0efLTuI2wcacviaKXCSBAtPbHPPnk/8YmKoapbrpL45EoKGoRVtnSLOLg6uSIKU02 I2xrbne/9aIID0BPMK8p8YL6/07VwSL4IgCUs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+/ynut0iJL/DEdla9rraSr6b+opihwye7oBaNpDLvJo=; b=hvdSv/vw4qrhuaUTBpU/8lVnbrJjF31a5hyRpwOp+RVprl0QZIZyzMESk8oJ4XHDC8 osM5K/ewDl+X1vIhSsrLItAjU+dqNbKHktFaKiDxqqf+/XnQOdXsvtJpa0S6RnS/QIr/ lHIAUG/PV7878bd4CI19tCBOa7R6XgNHND1DCa5O45kWiAXKm3wGJi2CIG5/stxlSH8M Awe0v0V958gVTrrEiw3voceJ6c7wAkDfTAlwrprrX1UZbrbHwtmo2R9bOq6nSJ7oTiH8 lxt5dtzHy+JauN70kcSg52oAeqjv7VgkLPmZKPkqYFLu1P2YYqXyJmQIFm1i2S/uGO2f BCSg== X-Gm-Message-State: AHQUAubiP07nSPRaRNN2YohJ2X5OEebtJekWIeoO0sGlg1bTi2O2N0E9 iFhjysShB3rQLR3boylUZ4FYEctwk24= X-Google-Smtp-Source: AHgI3IY46enrPmplPdnANyqLDEb2qT4WRM2BqvMo/sOQW4cOAm6rK1YmpmnLgfuYIU3yo7ezmHfyDQ== X-Received: by 2002:a62:6e07:: with SMTP id j7mr2160747pfc.135.1549326666991; Mon, 04 Feb 2019 16:31:06 -0800 (PST) Received: from chcunningham-linux.sea.corp.google.com ([2620:15c:38:200:74b:ad27:5acb:a21]) by smtp.gmail.com with ESMTPSA id l85sm1950283pfg.161.2019.02.04.16.31.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Feb 2019 16:31:06 -0800 (PST) From: chcunningham To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Feb 2019 16:30:29 -0800 Message-Id: <20190205003029.1999-1-chcunningham@chromium.org> X-Mailer: git-send-email 2.20.1.611.gfbb209baf1-goog In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov: validate chunk_count vs stsc_data 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" Bad content may contain stsc boxes with a first_chunk index that exceeds stco.entries (chunk_count). This ammends the existing check to include cases where chunk_count == 0. --- libavformat/mov.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 9b9739f788..2f3ad38ac3 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2694,8 +2694,11 @@ static inline int64_t mov_get_stsc_samples(MOVStreamContext *sc, unsigned int in if (mov_stsc_index_valid(index, sc->stsc_count)) chunk_count = sc->stsc_data[index + 1].first - sc->stsc_data[index].first; - else + else { + // Validation for stsc / stco happens earlier in mov_read_stsc + mov_read_trak. + av_assert0(sc->stsc_data[index].first <= sc->chunk_count); chunk_count = sc->chunk_count - (sc->stsc_data[index].first - 1); + } return sc->stsc_data[index].count * (int64_t)chunk_count; } @@ -4175,7 +4178,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) st->index); return 0; } - if (sc->chunk_count && sc->stsc_count && sc->stsc_data[ sc->stsc_count - 1 ].first > sc->chunk_count) { + 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;