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:
parent
89f0604d89
commit
52ed40656b
@ -410,15 +410,17 @@ AudioSource::read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos
|
|||||||
|
|
||||||
/* fix for near-end-of-file conditions */
|
/* 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;
|
// 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);
|
read_npeaks = min ((samplecnt_t) floor (cnt / samples_per_visual_peak), npeaks);
|
||||||
zero_fill = npeaks - read_npeaks;
|
zero_fill = npeaks - read_npeaks;
|
||||||
expected_peaks = (cnt / (double) samples_per_file_peak);
|
expected_peaks = (cnt / (double) samples_per_file_peak);
|
||||||
scale = npeaks/expected_peaks;
|
scale = npeaks/expected_peaks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert (cnt >= 0);
|
||||||
|
|
||||||
// cerr << "actual npeaks = " << read_npeaks << " zf = " << zero_fill << endl;
|
// cerr << "actual npeaks = " << read_npeaks << " zf = " << zero_fill << endl;
|
||||||
|
|
||||||
if (npeaks == cnt) {
|
if (npeaks == cnt) {
|
||||||
|
Loading…
Reference in New Issue
Block a user