From 5ffba8631dfba4bfb35b39a476911701b7d1034d Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Fri, 29 Jan 2010 01:09:41 +0000 Subject: [PATCH] SCI: Fix out-of-bounds error in MT-32 patch reading in GM mode. svn-id: r47662 --- engines/sci/sound/drivers/midi.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/engines/sci/sound/drivers/midi.cpp b/engines/sci/sound/drivers/midi.cpp index 9ce34aa9ebc..8e65cb96d52 100644 --- a/engines/sci/sound/drivers/midi.cpp +++ b/engines/sci/sound/drivers/midi.cpp @@ -659,10 +659,15 @@ void MidiPlayer_Midi::mapMt32ToGm(byte *data, size_t size) { debugCN(kDebugLevelSound, "%s -> ", Mt32PresetTimbreMaps[number].name); break; case 2: - strncpy(name, (const char *)data + 0x1ec + number * 0xf6, 10); - name[10] = 0; - _patchMap[i] = lookupGmInstrument(name); - debugCN(kDebugLevelSound, "%s -> ", name); + if (number < memtimbres) { + strncpy(name, (const char *)data + 0x1ec + number * 0xf6, 10); + name[10] = 0; + _patchMap[i] = lookupGmInstrument(name); + debugCN(kDebugLevelSound, "%s -> ", name); + } else { + _patchMap[i] = 0xff; + debugCN(kDebugLevelSound, "[Invalid] -> "); + } break; case 3: _patchMap[i] = getGmInstrument(Mt32RhythmTimbreMaps[number]);