From: <sv...@op...> - 2024-11-24 12:53:52
|
Author: sagamusix Date: Sun Nov 24 13:53:45 2024 New Revision: 22282 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22282 Log: Merged revision(s) 22225 from trunk/OpenMPT: [Fix] When an instrument refers to an invalid sample slot, don't try to address it during playback. The playback routines have no issue with this (due to all possible sample slots being pre-allocated), but some code in the tracker that tries to infer the sample slot from pModSample pointer and assumes that it's always valid could crash due to this (e.g. unused sample scanner). Instead, refer to sample slot 0 when such a note mapping is encountered. ........ Modified: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/soundlib/Snd_fx.cpp Modified: branches/OpenMPT-1.31/soundlib/Snd_fx.cpp ============================================================================== --- branches/OpenMPT-1.31/soundlib/Snd_fx.cpp Sun Nov 24 13:42:37 2024 (r22281) +++ branches/OpenMPT-1.31/soundlib/Snd_fx.cpp Sun Nov 24 13:53:45 2024 (r22282) @@ -1391,7 +1391,7 @@ if(pIns->NoteMap[note - NOTE_MIN] > NOTE_MAX) return; uint32 n = pIns->Keyboard[note - NOTE_MIN]; - pSmp = ((n) && (n < MAX_SAMPLES)) ? &Samples[n] : nullptr; + pSmp = (n <= GetNumSamples()) ? &Samples[n] : &Samples[0]; } else if(GetNumInstruments()) { // No valid instrument, or not a valid note. @@ -1751,9 +1751,9 @@ if((pIns) && (note - NOTE_MIN < (int)std::size(pIns->Keyboard))) { uint32 n = pIns->Keyboard[note - NOTE_MIN]; - if((n) && (n < MAX_SAMPLES)) + if(n > 0) { - pSmp = &Samples[n]; + pSmp = &Samples[(n <= GetNumSamples()) ? n : 0]; } else if(m_playBehaviour[kITEmptyNoteMapSlot] && !chn.HasMIDIOutput()) { // Impulse Tracker ignores empty slots. @@ -2229,9 +2229,9 @@ // Test case: dct_smp_note_test.it if(!m_playBehaviour[kITDCTBehaviour] || !m_playBehaviour[kITRealNoteMapping]) dnaNote = pIns->NoteMap[note - NOTE_MIN]; - if(smp > 0 && smp < MAX_SAMPLES) + if(smp > 0) { - pSample = &Samples[smp]; + pSample = &Samples[(smp <= GetNumSamples()) ? smp : 0]; } else if(m_playBehaviour[kITEmptyNoteMapSlot] && !pIns->HasValidMIDIChannel()) { // Impulse Tracker ignores empty slots. |