mirror of
https://git.eden-emu.dev/archive/citron
synced 2026-04-11 21:58:49 -04:00
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:
@@ -33,8 +33,26 @@ u32 EffectContext::GetCount() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EffectContext::UpdateStateByDspShared() {
|
void EffectContext::UpdateStateByDspShared() {
|
||||||
for (size_t i = 0; i < dsp_state_count; i++) {
|
// Ensure we don't exceed the bounds of any of the spans
|
||||||
effect_infos[i].UpdateResultState(result_states_cpu[i], result_states_dsp[i]);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user