Skip to content

Commit

Permalink
[Fix] MED: Avoid undefined behaviour with out-of-range echo depth par…
Browse files Browse the repository at this point in the history
…ameter (found with afl++ + ubsan).

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22221 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Nov 18, 2024
1 parent 2676a00 commit c8c67ca
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions soundlib/Load_med.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1388,9 +1388,9 @@ bool CSoundFile::ReadMED(FileReader &file, ModLoadingFlags loadFlags)
if((header.mixEchoType == 1 || header.mixEchoType == 2) && numPlugins < MAX_MIXPLUGINS)
{
// Emulating MED echo using the DMO echo requires to compensate for the differences in initial feedback in the latter.
const float feedback = 1.0f / (1 << std::max(header.mixEchoDepth, uint8(1))); // The feedback we want
const float initialFeedback = std::sqrt(1.0f - (feedback * feedback)); // Actual strength of first delay's feedback
const float wetFactor = feedback / initialFeedback; // Factor to compensate for this
const float feedback = 1.0f / (1 << std::clamp(header.mixEchoDepth, uint8(1), uint8(9))); // The feedback we want
const float initialFeedback = std::sqrt(1.0f - (feedback * feedback)); // Actual strength of first delay's feedback
const float wetFactor = feedback / initialFeedback; // Factor to compensate for this
const float delay = (std::max(header.mixEchoLength.get(), uint16(1)) - 1) / 1999.0f;
SNDMIXPLUGIN &mixPlug = m_MixPlugins[numPlugins];
mpt::reconstruct(mixPlug);
Expand Down

0 comments on commit c8c67ca

Please sign in to comment.