13
0

Fix 30dc9ccc86, buf2 needs to remain in scope.

This fixes a heap-use-after-free.
This commit is contained in:
Robin Gareus 2024-11-06 17:24:00 +01:00
parent a6e2f856a2
commit 5f2371a9e2
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -932,6 +932,7 @@ AudioSource::compute_and_write_peaks (Sample const * buf, samplecnt_t first_samp
samplecnt_t samples_done;
const size_t blocksize = (128 * 1024);
off_t first_peak_byte;
std::unique_ptr<Sample[]> buf2;
if (-1 == _peakfile_fd) {
if (prepare_for_peakfile_writes ()) {
@ -991,7 +992,7 @@ AudioSource::compute_and_write_peaks (Sample const * buf, samplecnt_t first_samp
/* make a new contiguous buffer containing leftovers and the new stuff */
to_do = cnt + peak_leftover_cnt;
std::unique_ptr<Sample[]> buf2(new Sample[to_do]);
buf2.reset(new Sample[to_do]);
/* the remnants */
memcpy (buf2.get(), peak_leftovers, peak_leftover_cnt * sizeof (Sample));