From 2a0bb79513ab4280d95f86df43751b06cdc5cb8a Mon Sep 17 00:00:00 2001 From: Nik Date: Sun, 1 Dec 2024 16:07:24 +0100 Subject: [PATCH] fix: Potential overflow when calculating audio sample index Fixes [https://github.com/WerWolv/ImHex/security/code-scanning/223](https://github.com/WerWolv/ImHex/security/code-scanning/223) To fix the problem, we need to ensure that the multiplication is performed using a larger integer type to avoid overflow. This can be achieved by casting one of the operands to `u64` before performing the multiplication. This way, the multiplication will be done in the larger type, preventing overflow. We will modify the line `index += frameCount * device->playback.channels;` to cast `frameCount` to `u64` before the multiplication. _Suggested fixes powered by Copilot Autofix. Review carefully before merging._ Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- plugins/visualizers/source/content/pl_visualizers/sound.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/visualizers/source/content/pl_visualizers/sound.cpp b/plugins/visualizers/source/content/pl_visualizers/sound.cpp index 2c5b6f324..f7b4a6b74 100644 --- a/plugins/visualizers/source/content/pl_visualizers/sound.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/sound.cpp @@ -56,7 +56,7 @@ namespace hex::plugin::visualizers { } ma_copy_pcm_frames(pOutput, waveData.data() + index, frameCount, device->playback.format, device->playback.channels); - index += frameCount * device->playback.channels; + index += static_cast(frameCount) * device->playback.channels; }; ma_device_init(nullptr, &deviceConfig, &audioDevice);