From patchwork Fri Feb 1 01:18:26 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: 11937 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 0C77544DA23 for ; Fri, 1 Feb 2019 03:25:58 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 292AF68AC02; Fri, 1 Feb 2019 03:25:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 546B868AA78 for ; Fri, 1 Feb 2019 03:25:40 +0200 (EET) Received: by mail-pf1-f195.google.com with SMTP id c123so2346771pfb.0 for ; Thu, 31 Jan 2019 17:26:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=q/pddYOKmxRf2lBGIFgpbeuPoLHQT3q9hRnWaWimbSA=; b=feRv8RgJUbZe50JCS+Rae/Fd1OPeaalC1wvuGQd1oCE/t+LrGZGIMAlqwLydoKmDFl 4yskOn/8jjHBWtsdjQjSzlP2gpfOdAl+G+TpkjZsw5hE38WGql1Ga3K0Cxg4H66tfTL2 DFW54PJi0ncFMwLAOSdnq+nsfZ8QbTtWjD6Sg= 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:mime-version :content-transfer-encoding; bh=q/pddYOKmxRf2lBGIFgpbeuPoLHQT3q9hRnWaWimbSA=; b=jZn9WfcasyGhzqQvWCE5lro0F0OZ3PEejBzSSgD6d6d0XtBYpNE4T/EwUibwKOY5+o Emuow7/RKG//J0E2pktNCQDBuT8lMnacemCg+oNIzauQeYLBIA1KR2Ih5tKAX2E93v+z TrZra67fnmaBE12eNQXXXSOgSxL5+lxeCFeqYiAfSzEf0cpoFK1dVda5BTzcsIuPKhVx RrkIffg9p3sT7R8vSmnqhpQDfoBkD7Q2svk3TObMQ/L8KDmetHHtAMzocq5GKL8cuMTF f+iBFQSxxfXw/EEi81ye7mmke6tjkWyuJ2019DAiVuJSz+Qu7t3BPctzxJLR67Hi4xcx UBZA== X-Gm-Message-State: AJcUukdlGc1WuYDTUrSeAWGpaKat+y+uavmV0oPscAUj1mTbzSXopxNz Yu11N6b/Qc70kxOxey9jAL9YlGcjaEg= X-Google-Smtp-Source: ALg8bN6jD6LDpnCkHgVKBuxChFQMboiegWEozPKklzKA1IuDNKSD+jAVUzQs9UvK+AHm1Zyih0yyyw== X-Received: by 2002:a62:5c41:: with SMTP id q62mr37819827pfb.171.1548983916093; Thu, 31 Jan 2019 17:18:36 -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 r66sm10580568pfk.157.2019.01.31.17.18.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jan 2019 17:18:35 -0800 (PST) From: chcunningham To: ffmpeg-devel@ffmpeg.org Date: Thu, 31 Jan 2019 17:18:26 -0800 Message-Id: <20190201011826.23766-1-chcunningham@chromium.org> X-Mailer: git-send-email 2.20.1.611.gfbb209baf1-goog 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. Also updates MOVStsc to use unsigned ints, per spec. --- libavformat/isom.h | 6 +++--- libavformat/mov.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index e629663949..8e0d8355b3 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -59,9 +59,9 @@ typedef struct MOVStts { } MOVStts; typedef struct MOVStsc { - int first; - int count; - int id; + unsigned int first; + unsigned int count; + unsigned int id; } MOVStsc; typedef struct MOVElst { 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;