From: <sv...@op...> - 2024-11-24 00:32:25
|
Author: sagamusix Date: Sun Nov 24 01:32:17 2024 New Revision: 22267 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22267 Log: Merged revision(s) 22221, 22224, 22226, 22230, 22232, 22241 from trunk/OpenMPT: [Fix] MED: Avoid undefined behaviour with out-of-range echo depth parameter (found with afl++ + ubsan). ........ [Fix] Avoid extremely loud sample and synth amplification outside of supported GUI parameters. Found with afl++ + ubsan. ........ [Fix] Tuning: Apply a (hopefully small enough) epsilon to tuning ratio setting to avoid NaN and inf results in tuning frequency calculation. Found with afl++ + ubsan. ........ [Fix] Avoid integer wraparound when period + fractional period exceeds 32-bit integer limits. Found with afl++ + ubsan. ........ [Fix] I3DL2Reverb: Avoid NaNs in room filter calculation. Found with afl++ + ubsan. ........ [Fix] Also limit sample pre-amp to 2000 for formats where we retrieve it through other means than OpenMPT song extensions (e.g. MO3). Found with afl++ + ubsan. [Fix] Sanitize sample length and loop points for missing external samples as well. Otherwise invalid values might be used during seeking. Found with afl++ + ubsan. ........ Modified: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/soundlib/Load_it.cpp branches/OpenMPT-1.31/soundlib/Load_med.cpp branches/OpenMPT-1.31/soundlib/Sndfile.cpp branches/OpenMPT-1.31/soundlib/Sndmix.cpp branches/OpenMPT-1.31/soundlib/plugins/dmo/I3DL2Reverb.cpp branches/OpenMPT-1.31/soundlib/tuning.h Modified: branches/OpenMPT-1.31/soundlib/Load_it.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/Load_it.cpp Sun Nov 24 01:22:55 2024 (r22266) +++ branches/OpenMPT-1.31/soundlib/Load_it.cpp Sun Nov 24 01:32:17 2024 (r22267) @@ -2668,14 +2668,6 @@ m_nMixLevels = MixLevels::Original; //m_dwCreatedWithVersion //m_dwLastSavedWithVersion - //m_nSamplePreAmp - //m_nVSTiVolume - //m_nDefaultGlobalVolume - LimitMax(m_nDefaultGlobalVolume, MAX_GLOBAL_VOLUME); - //m_nRestartPos - //m_ModFlags - LimitMax(m_nDefaultRowsPerBeat, MAX_ROWS_PER_BEAT); - LimitMax(m_nDefaultRowsPerMeasure, MAX_ROWS_PER_BEAT); return true; } Modified: branches/OpenMPT-1.31/soundlib/Load_med.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/Load_med.cpp Sun Nov 24 01:22:55 2024 (r22266) +++ branches/OpenMPT-1.31/soundlib/Load_med.cpp Sun Nov 24 01:32:17 2024 (r22267) @@ -1195,9 +1195,9 @@ 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); Modified: branches/OpenMPT-1.31/soundlib/Sndfile.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/Sndfile.cpp Sun Nov 24 01:22:55 2024 (r22266) +++ branches/OpenMPT-1.31/soundlib/Sndfile.cpp Sun Nov 24 01:32:17 2024 (r22267) @@ -594,6 +594,8 @@ for(SAMPLEINDEX nSmp = 1; nSmp <= m_nSamples; nSmp++) { ModSample &sample = Samples[nSmp]; + LimitMax(sample.nLength, MAX_SAMPLE_LENGTH); + sample.SanitizeLoops(); #ifdef MPT_EXTERNAL_SAMPLES if(SampleHasPath(nSmp)) @@ -662,6 +664,8 @@ LimitMax(m_nDefaultRowsPerBeat, MAX_ROWS_PER_BEAT); LimitMax(m_nDefaultRowsPerMeasure, MAX_ROWS_PER_BEAT); LimitMax(m_nDefaultGlobalVolume, MAX_GLOBAL_VOLUME); + LimitMax(m_nSamplePreAmp, 2000); + LimitMax(m_nVSTiVolume, 2000); if(!m_tempoSwing.empty()) m_tempoSwing.resize(m_nDefaultRowsPerBeat); Modified: branches/OpenMPT-1.31/soundlib/Sndmix.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/Sndmix.cpp Sun Nov 24 01:22:55 2024 (r22266) +++ branches/OpenMPT-1.31/soundlib/Sndmix.cpp Sun Nov 24 01:32:17 2024 (r22267) @@ -1840,8 +1840,15 @@ vdelta += Util::muldiv(period, fineUpTable[l & 0x03], 0x10000) - period; } } - period = (period + vdelta) / 256; - nPeriodFrac = vdelta & 0xFF; + if(Util::MaxValueOfType(period) - period >= vdelta) + { + period = (period + vdelta) / 256; + nPeriodFrac = vdelta & 0xFF; + } else + { + period = Util::MaxValueOfType(period) / 256; + nPeriodFrac = 0; + } } else { // MPT's autovibrato code Modified: branches/OpenMPT-1.31/soundlib/plugins/dmo/I3DL2Reverb.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/plugins/dmo/I3DL2Reverb.cpp Sun Nov 24 01:22:55 2024 (r22266) +++ branches/OpenMPT-1.31/soundlib/plugins/dmo/I3DL2Reverb.cpp Sun Nov 24 01:32:17 2024 (r22267) @@ -505,7 +505,7 @@ m_roomFilter = 0.0f; } else { - float freq = std::cos(HFReference() * (2.0f * mpt::numbers::pi_v<float>) / m_effectiveSampleRate); + float freq = std::min(std::cos(HFReference() * (2.0f * mpt::numbers::pi_v<float>) / m_effectiveSampleRate), 0.9999f); float roomFilter = (freq * (roomHF + roomHF) - 2.0f + std::sqrt(freq * (roomHF * roomHF * freq * 4.0f) + roomHF * 8.0f - roomHF * roomHF * 4.0f - roomHF * freq * 8.0f)) / (roomHF + roomHF - 2.0f); m_roomFilter = Clamp(roomFilter, 0.0f, 1.0f); } Modified: branches/OpenMPT-1.31/soundlib/tuning.h ============================================================================== --- branches/OpenMPT-1.31/soundlib/tuning.h Sun Nov 24 01:22:55 2024 (r22266) +++ branches/OpenMPT-1.31/soundlib/tuning.h Sun Nov 24 01:32:17 2024 (r22267) @@ -224,7 +224,8 @@ static bool IsValidRatio(RATIOTYPE ratio) { - return (ratio > static_cast<RATIOTYPE>(0.0)); + // Arbitrary epsilon > 0 to avoid NaNs and infinite values in ratio calculation + return (ratio > static_cast<RATIOTYPE>(0.02f)); } private: |