From: <sv...@op...> - 2024-11-24 00:34:18
|
Author: sagamusix Date: Sun Nov 24 01:34:11 2024 New Revision: 22269 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22269 Log: Merged revision(s) 22224, 22226, 22230, 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] 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.29/ (props changed) branches/OpenMPT-1.29/soundlib/Load_it.cpp branches/OpenMPT-1.29/soundlib/Sndfile.cpp branches/OpenMPT-1.29/soundlib/Sndmix.cpp branches/OpenMPT-1.29/soundlib/tuning.h Modified: branches/OpenMPT-1.29/soundlib/Load_it.cpp ============================================================================== --- branches/OpenMPT-1.29/soundlib/Load_it.cpp Sun Nov 24 01:33:10 2024 (r22268) +++ branches/OpenMPT-1.29/soundlib/Load_it.cpp Sun Nov 24 01:34:11 2024 (r22269) @@ -2476,14 +2476,6 @@ m_nMixLevels = mixLevelsOriginal; //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.29/soundlib/Sndfile.cpp ============================================================================== --- branches/OpenMPT-1.29/soundlib/Sndfile.cpp Sun Nov 24 01:33:10 2024 (r22268) +++ branches/OpenMPT-1.29/soundlib/Sndfile.cpp Sun Nov 24 01:34:11 2024 (r22269) @@ -493,6 +493,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)) @@ -559,6 +561,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.29/soundlib/Sndmix.cpp ============================================================================== --- branches/OpenMPT-1.29/soundlib/Sndmix.cpp Sun Nov 24 01:33:10 2024 (r22268) +++ branches/OpenMPT-1.29/soundlib/Sndmix.cpp Sun Nov 24 01:34:11 2024 (r22269) @@ -1806,8 +1806,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.29/soundlib/tuning.h ============================================================================== --- branches/OpenMPT-1.29/soundlib/tuning.h Sun Nov 24 01:33:10 2024 (r22268) +++ branches/OpenMPT-1.29/soundlib/tuning.h Sun Nov 24 01:34:11 2024 (r22269) @@ -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: |