From patchwork Sat Feb 2 02:25:19 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: 11951 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 E3F7B445D38 for ; Sat, 2 Feb 2019 04:33:43 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B97DF68A7A4; Sat, 2 Feb 2019 04:33:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 414C268A7A0 for ; Sat, 2 Feb 2019 04:33:37 +0200 (EET) Received: by mail-pl1-f195.google.com with SMTP id a14so4124361plm.12 for ; Fri, 01 Feb 2019 18:33:37 -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=njEVUjhL68vFLE0RMqxOGgggw5OJjWHHZHaBn+EnEHQ=; b=fwi95RyUVmwM7ie7bwhUcXNHN7jKhCq2Pu88UOFbQKZWtIOsuGzeaqbp+04skdD2aC YG+y0mqV7F/fyxKSN4bWmbyWeT1o4Q4qZ8dmTjXq12QS4Qkk9mn1J5/1PtZFTCaSqXHm 2BJCuiKK8Pl3Ioew8o0tMACVMHlM48y0fnyG8= 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=njEVUjhL68vFLE0RMqxOGgggw5OJjWHHZHaBn+EnEHQ=; b=fyX4i18bVra7BpW4myaiop1R+kvjBee02QoiBqv+8qeEJYBFr+fN3QFFfvF6JLWa9q Ppc0SSwmuTVwuyzx09jnS6jUOzuX3CsY3UksGvi3aVTdpV6T6pojf5M+Yn8EGJ+hceZu KeNXexjsC6lUGbSiTUvVvs/2dFVj2Il+W/WcM8y9moWF6/GMhnxBaKnXBQ7KptLzzXT2 LDu2nVeQQpRBr6brMTxUu4JeU3NeTbYgwWTnWOdUnwfsptiT3zDZL9dn1tTueaURp9sX xjginuYZvotv9Iwe1IdntIfBlR0w5pNX6hgK+jzBHge44hJ9fsG2ZiQHh1l+B6eLdu+b G19Q== X-Gm-Message-State: AJcUukeY0L6KR4O3uRAYQYepyUUuYf3MprYph+FI9tfmDh3OQ6CgiQgc 2fP/W+xthpQM96VdUvGS/nZnG8sb7To= X-Google-Smtp-Source: ALg8bN6N1brIB5/uoTDtI2hmE+YrRDR9qhbwreGBTkZmBMLMNolePf2gAxDAXOQvdwzjcfQuH5g4kw== X-Received: by 2002:a17:902:209:: with SMTP id 9mr42952492plc.288.1549074373554; Fri, 01 Feb 2019 18:26:13 -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 p67sm12942979pfg.44.2019.02.01.18.26.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Feb 2019 18:26:12 -0800 (PST) From: chcunningham To: ffmpeg-devel@ffmpeg.org Date: Fri, 1 Feb 2019 18:25:19 -0800 Message-Id: <20190202022519.24932-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). mov_get_stsc_samples now checks for this and returns 0 when values are invalid. --- libavformat/mov.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 9b9739f788..dcf4ee8dc1 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2690,11 +2690,11 @@ static inline int mov_stsc_index_valid(unsigned int index, unsigned int count) /* Compute the samples value for the stsc entry at the given index. */ static inline int64_t mov_get_stsc_samples(MOVStreamContext *sc, unsigned int index) { - int chunk_count; + unsigned int chunk_count = 0; if (mov_stsc_index_valid(index, sc->stsc_count)) chunk_count = sc->stsc_data[index + 1].first - sc->stsc_data[index].first; - else + else if (sc->chunk_count >= sc->stsc_data[index].first) chunk_count = sc->chunk_count - (sc->stsc_data[index].first - 1); return sc->stsc_data[index].count * (int64_t)chunk_count;