fix(audio): add bounds checking in EffectContext::UpdateStateByDspShared

- Calculate max_count to prevent out-of-bounds access
- Validate effect type before calling UpdateResultState
- Add try-catch for exception handling from corrupted effects
- Prevent crashes from invalid effect data

Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
Zephyron
2025-12-04 19:43:55 +10:00
parent 60d7af07de
commit 3c0a3da873

View File

@@ -33,8 +33,26 @@ u32 EffectContext::GetCount() const {
}
void EffectContext::UpdateStateByDspShared() {
for (size_t i = 0; i < dsp_state_count; i++) {
effect_infos[i].UpdateResultState(result_states_cpu[i], result_states_dsp[i]);
// Ensure we don't exceed the bounds of any of the spans
const size_t max_count = std::min({dsp_state_count,
static_cast<size_t>(effect_infos.size()),
static_cast<size_t>(result_states_cpu.size()),
static_cast<size_t>(result_states_dsp.size())});
for (size_t i = 0; i < max_count; i++) {
try {
// Validate effect type before calling virtual function to prevent crashes from corrupted data
const auto effect_type = effect_infos[i].GetType();
if (effect_type == EffectInfoBase::Type::Invalid) {
// Skip invalid effects
continue;
}
effect_infos[i].UpdateResultState(result_states_cpu[i], result_states_dsp[i]);
} catch (...) {
// If UpdateResultState throws (e.g., due to corrupted effect data), skip this effect
// This prevents crashes from corrupted audio effect data
continue;
}
}
}