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.
This commit is contained in:
Robin Gareus 2018-03-08 00:37:54 +01:00
parent 89f0604d89
commit 52ed40656b
1 changed files with 4 additions and 2 deletions

View File

@ -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) {