From b108695b9b26a3d89dad1c31997648b791757bb1 Mon Sep 17 00:00:00 2001 From: Tom Finegan Date: Mon, 31 Aug 2015 11:06:58 -0700 Subject: [PATCH] mkvparser: Segment::AppendCluster asserts to error checks. Change-Id: Id6bb378b22a7c6397e3d950c2fdd84396279e881 --- mkvparser.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mkvparser.cpp b/mkvparser.cpp index 69e4424..e50322b 100644 --- a/mkvparser.cpp +++ b/mkvparser.cpp @@ -1277,16 +1277,16 @@ long Segment::DoLoadClusterUnknownSize(long long& pos, long& len) { } bool Segment::AppendCluster(Cluster* pCluster) { - assert(pCluster); - assert(pCluster->m_index >= 0); + if (pCluster == NULL || pCluster->m_index < 0) + return false; const long count = m_clusterCount + m_clusterPreloadCount; long& size = m_clusterSize; - assert(size >= count); - const long idx = pCluster->m_index; - assert(idx == m_clusterCount); + + if (size < count || idx != m_clusterCount) + return false; if (count >= size) { const long n = (size <= 0) ? 2048 : 2 * size; @@ -1294,8 +1294,8 @@ bool Segment::AppendCluster(Cluster* pCluster) { Cluster** const qq = new (std::nothrow) Cluster*[n]; if (qq == NULL) return false; - Cluster** q = qq; + Cluster** q = qq; Cluster** p = m_clusters; Cluster** const pp = p + count; @@ -1309,18 +1309,18 @@ bool Segment::AppendCluster(Cluster* pCluster) { } if (m_clusterPreloadCount > 0) { - assert(m_clusters); - Cluster** const p = m_clusters + m_clusterCount; - assert(*p); - assert((*p)->m_index < 0); + if (*p == NULL || (*p)->m_index >= 0) + return false; Cluster** q = p + m_clusterPreloadCount; - assert(q < (m_clusters + size)); + if (q >= (m_clusters + size)) + return false; for (;;) { Cluster** const qq = q - 1; - assert((*qq)->m_index < 0); + if ((*qq)->m_index >= 0) + return false; *q = *qq; q = qq;