From 7f96dbc0242f169caeb8461237bc01a23c115f56 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 20 Aug 2023 03:56:30 -0300 Subject: [PATCH] Fix invalid audio renderer buffer size when end offset < start offset (#5588) * Fix invalid audio renderer buffer size when end offset < start offset * Fix possible overflow on IsSampleOffsetInRangeForPcm --- src/Ryujinx.Audio/Renderer/Dsp/PcmHelper.cs | 5 +++++ src/Ryujinx.Audio/Renderer/Parameter/VoiceInParameter.cs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Audio/Renderer/Dsp/PcmHelper.cs b/src/Ryujinx.Audio/Renderer/Dsp/PcmHelper.cs index d209c515..8134e6b7 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/PcmHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/PcmHelper.cs @@ -20,6 +20,11 @@ namespace Ryujinx.Audio.Renderer.Dsp [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetBufferSize(int startSampleOffset, int endSampleOffset, int offset, int count) where T : unmanaged { + if (endSampleOffset < startSampleOffset) + { + return 0; + } + return GetCountToDecode(startSampleOffset, endSampleOffset, offset, count) * Unsafe.SizeOf(); } diff --git a/src/Ryujinx.Audio/Renderer/Parameter/VoiceInParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/VoiceInParameter.cs index 86f92442..f33d82aa 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/VoiceInParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/VoiceInParameter.cs @@ -264,8 +264,8 @@ namespace Ryujinx.Audio.Renderer.Parameter { uint dataTypeSize = (uint)Unsafe.SizeOf(); - return StartSampleOffset * dataTypeSize <= Size && - EndSampleOffset * dataTypeSize <= Size; + return (ulong)StartSampleOffset * dataTypeSize <= Size && + (ulong)EndSampleOffset * dataTypeSize <= Size; } ///