From 52ed40656b5e3626eda22e394577267762dddf0a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 8 Mar 2018 00:37:54 +0100 Subject: 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. --- libs/ardour/audiosource.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libs/ardour/audiosource.cc') 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) { -- cgit v1.2.3