From 346909f8b27deb0c46c137b66826ab9e192cb6a7 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Thu, 31 Oct 2024 11:21:54 -0400 Subject: [PATCH] Fix a boudns bug that could crash empty zones The unison fix resulted in an oob array read which could speciously cause crashes. Fix. Also note to self - do an ASAN run soon! --- src/voice/voice.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/voice/voice.cpp b/src/voice/voice.cpp index ef066f90..eec4bd79 100644 --- a/src/voice/voice.cpp +++ b/src/voice/voice.cpp @@ -255,9 +255,18 @@ template bool Voice::processWithOS() auto fpitch = calculateVoicePitch(); auto [firstIndex, lastIndex] = sampleIndexRange(); - for (auto i = firstIndex; i < lastIndex; ++i) - if (zone->samplePointers[i]) - calculateGeneratorRatio(fpitch, i, i - firstIndex); + if (firstIndex >= 0) + { + for (auto i = firstIndex; i < lastIndex; ++i) + { + assert(i >= 0); + assert(i < zone->samplePointers.size()); + if (zone->samplePointers[i]) + { + calculateGeneratorRatio(fpitch, i, i - firstIndex); + } + } + } if (useOversampling) for (auto i = 0; i < numGeneratorsActive; ++i) @@ -874,13 +883,13 @@ std::pair Voice::sampleIndexRange() const if (zone->variantData.variantPlaybackMode == engine::Zone::UNISON) { - firstIndex = 0; lastIndex = 0; for (int i = 0; i < maxVariantsPerZone; ++i) { if (zone->variantData.variants[i].active) { + firstIndex = 0; lastIndex++; } }