Skip to content

Commit

Permalink
Fix buffer overrun in WaveformMath
Browse files Browse the repository at this point in the history
32 excess samples were read from the preset state in waveform modes. Didn't have any noticeable impact, but we should clearly not read over the end of an array.
  • Loading branch information
kblaschke committed Feb 6, 2024
1 parent bd7d557 commit 3278e14
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/libprojectM/MilkdropPreset/Waveforms/WaveformMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,30 @@ namespace Waveforms {
auto WaveformMath::GetVertices(const PresetState& presetState,
const PerFrameContext& presetPerFrameContext) -> std::array<VertexList, 2>
{
static_assert(libprojectM::Audio::WaveformSamples <= WaveformMaxPoints, "WaveformMaxPoints is larger than WaveformSamples");
static_assert(WaveformMaxPoints >= libprojectM::Audio::SpectrumSamples, "WaveformMaxPoints is smaller than SpectrumSamples");
static_assert(WaveformMaxPoints >= libprojectM::Audio::WaveformSamples, "WaveformMaxPoints is smaller than WaveformSamples");

using libprojectM::Audio::WaveformSamples;

// Get the correct audio sample type for the current waveform mode.
if (IsSpectrumWave())
{
std::copy(begin(presetState.audioData.spectrumLeft),
begin(presetState.audioData.spectrumLeft) + WaveformMaxPoints,
begin(presetState.audioData.spectrumLeft) + Audio::SpectrumSamples,
begin(m_pcmDataL));

std::copy(begin(presetState.audioData.spectrumRight),
begin(presetState.audioData.spectrumRight) + WaveformMaxPoints,
begin(presetState.audioData.spectrumRight) + Audio::SpectrumSamples,
begin(m_pcmDataR));
}
else
{
std::copy(begin(presetState.audioData.waveformLeft),
begin(presetState.audioData.waveformLeft) + WaveformMaxPoints,
begin(presetState.audioData.waveformLeft) + Audio::WaveformSamples,
begin(m_pcmDataL));

std::copy(begin(presetState.audioData.waveformRight),
begin(presetState.audioData.waveformRight) + WaveformMaxPoints,
begin(presetState.audioData.waveformRight) + Audio::WaveformSamples,
begin(m_pcmDataR));
}

Expand Down

0 comments on commit 3278e14

Please sign in to comment.