From: <sv...@op...> - 2024-11-24 00:33:18
|
Author: sagamusix Date: Sun Nov 24 01:33:10 2024 New Revision: 22268 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22268 Log: Merged revision(s) 22224, 22226, 22230, 22232, 22241 from trunk/OpenMPT: [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.30/ (props changed) branches/OpenMPT-1.30/soundlib/Load_it.cpp branches/OpenMPT-1.30/soundlib/Sndfile.cpp branches/OpenMPT-1.30/soundlib/Sndmix.cpp branches/OpenMPT-1.30/soundlib/plugins/dmo/I3DL2Reverb.cpp branches/OpenMPT-1.30/soundlib/tuning.h Modified: branches/OpenMPT-1.30/soundlib/Load_it.cpp ============================================================================== --- branches/OpenMPT-1.30/soundlib/Load_it.cpp Sun Nov 24 01:32:17 2024 (r22267) +++ branches/OpenMPT-1.30/soundlib/Load_it.cpp Sun Nov 24 01:33:10 2024 (r22268) @@ -2537,14 +2537,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); } Modified: branches/OpenMPT-1.30/soundlib/Sndfile.cpp ============================================================================== --- branches/OpenMPT-1.30/soundlib/Sndfile.cpp Sun Nov 24 01:32:17 2024 (r22267) +++ branches/OpenMPT-1.30/soundlib/Sndfile.cpp Sun Nov 24 01:33:10 2024 (r22268) @@ -500,6 +500,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)) @@ -568,6 +570,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.30/soundlib/Sndmix.cpp ============================================================================== --- branches/OpenMPT-1.30/soundlib/Sndmix.cpp Sun Nov 24 01:32:17 2024 (r22267) +++ branches/OpenMPT-1.30/soundlib/Sndmix.cpp Sun Nov 24 01:33:10 2024 (r22268) @@ -1823,8 +1823,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.30/soundlib/plugins/dmo/I3DL2Reverb.cpp ============================================================================== --- branches/OpenMPT-1.30/soundlib/plugins/dmo/I3DL2Reverb.cpp Sun Nov 24 01:32:17 2024 (r22267) +++ branches/OpenMPT-1.30/soundlib/plugins/dmo/I3DL2Reverb.cpp Sun Nov 24 01:33:10 2024 (r22268) @@ -506,7 +506,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.30/soundlib/tuning.h ============================================================================== --- branches/OpenMPT-1.30/soundlib/tuning.h Sun Nov 24 01:32:17 2024 (r22267) +++ branches/OpenMPT-1.30/soundlib/tuning.h Sun Nov 24 01:33:10 2024 (r22268) @@ -216,7 +216,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: |