Skip to content

Commit

Permalink
Fix a boudns bug that could crash empty zones (#1441)
Browse files Browse the repository at this point in the history
The unison fix resulted in an oob array read which could
speciously cause crashes. Fix.

Also note to self - do an ASAN run soon!
  • Loading branch information
baconpaul authored Oct 31, 2024
1 parent 3f5db41 commit f27674e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/voice/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,18 @@ template <bool OS> 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)
Expand Down Expand Up @@ -874,13 +883,13 @@ std::pair<int16_t, int16_t> 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++;
}
}
Expand Down

0 comments on commit f27674e

Please sign in to comment.