comparison data/model/Dense3DModelPeakCache.cpp @ 1192:9884efa1f88a spectrogram-minor-refactor

Fix potential crash in Dense3dModelPeakCache owing to combination of wrong width calculation and wrong handling of width overrun
author Chris Cannam
date Thu, 14 Jul 2016 14:49:04 +0100
parents 6d09ad2ab21f
children f5f83fb49852
comparison
equal deleted inserted replaced
1191:6d09ad2ab21f 1192:9884efa1f88a
86 Dense3DModelPeakCache::fillColumn(int column) const 86 Dense3DModelPeakCache::fillColumn(int column) const
87 { 87 {
88 Profiler profiler("Dense3DModelPeakCache::fillColumn"); 88 Profiler profiler("Dense3DModelPeakCache::fillColumn");
89 89
90 if (!in_range_for(m_coverage, column)) { 90 if (!in_range_for(m_coverage, column)) {
91 // see note in sourceModelChanged 91 if (m_coverage.size() > 0) {
92 if (m_coverage.size() > 0) m_coverage[m_coverage.size()-1] = false; 92 // The last peak may have come from an incomplete read, which
93 // may since have been filled, so reset it
94 m_coverage[m_coverage.size()-1] = false;
95 }
93 m_coverage.resize(column + 1, false); 96 m_coverage.resize(column + 1, false);
94 } 97 }
95 98
99 int sourceWidth = m_source->getWidth();
100
96 Column peak; 101 Column peak;
97 int n = 0; 102 int n = 0;
98 for (int i = 0; i < m_columnsPerPeak; ++i) { 103 for (int i = 0; i < m_columnsPerPeak; ++i) {
99 Column here = m_source->getColumn(column * m_columnsPerPeak + i); 104
105 int sourceColumn = column * m_columnsPerPeak + i;
106 if (sourceColumn >= sourceWidth) break;
107
108 Column here = m_source->getColumn(sourceColumn);
109
110 // cerr << "Dense3DModelPeakCache::fillColumn(" << column << "): source col "
111 // << sourceColumn << " of " << sourceWidth
112 // << " returned " << here.size() << " elts" << endl;
113
100 if (i == 0) { 114 if (i == 0) {
101 peak = here; 115 peak = here;
102 n = int(peak.size()); 116 n = int(peak.size());
103 } else { 117 } else {
104 int m = std::min(n, int(here.size())); 118 int m = std::min(n, int(here.size()));