summaryrefslogtreecommitdiff
path: root/libs/ardour/audiosource.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2018-03-08 00:37:54 +0100
committerRobin Gareus <robin@gareus.org>2018-03-08 00:37:54 +0100
commit52ed40656b5e3626eda22e394577267762dddf0a (patch)
treee27e74ac7c9354a202c7fc7df7e6bcc9a5bf1c9b /libs/ardour/audiosource.cc
parent89f0604d89dbb7e82d1580796df1b7f16b6023a1 (diff)
Safeguard against possibly invalid peak-requests
It may happen that WaveView requests a range that is larger than the data on disk. If start > _length, cnt becomes negative and the function will throw or segfault.
Diffstat (limited to 'libs/ardour/audiosource.cc')
-rw-r--r--libs/ardour/audiosource.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc
index 559a9c616d..6200b35d14 100644
--- a/libs/ardour/audiosource.cc
+++ b/libs/ardour/audiosource.cc
@@ -410,15 +410,17 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos
/* fix for near-end-of-file conditions */
- if (cnt > _length - start) {
+ if (cnt + start > _length) {
// cerr << "too close to end @ " << _length << " given " << start << " + " << cnt << " (" << _length - start << ")" << endl;
- cnt = _length - start;
+ cnt = std::max ((samplecnt_t)0, _length - start);
read_npeaks = min ((samplecnt_t) floor (cnt / samples_per_visual_peak), npeaks);
zero_fill = npeaks - read_npeaks;
expected_peaks = (cnt / (double) samples_per_file_peak);
scale = npeaks/expected_peaks;
}
+ assert (cnt >= 0);
+
// cerr << "actual npeaks = " << read_npeaks << " zf = " << zero_fill << endl;
if (npeaks == cnt) {