diff options
author | gdkchan <gab.dark.100@gmail.com> | 2022-10-04 20:12:54 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-04 20:12:54 -0300 |
commit | 60e16c15b6e9351371711356d205a12435b3c574 (patch) | |
tree | cbfa8d94a83752419defba6ca2a953d558e5c236 /Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs | |
parent | 2068445939e1b39f3e07f64aa11b93491d1116a7 (diff) |
Fix memory corruption in BCAT and FS Read methods when buffer is larger than needed (#3739)1.1.294
* Fix memory corruption in FS Read methods when buffer is larger than needed
* PR feedback
* nit: Don't move this around
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs')
-rw-r--r-- | Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs b/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs index fa5e05d6..878fcacf 100644 --- a/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs +++ b/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/IFile.cs @@ -19,7 +19,8 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy // Read(u32 readOption, u64 offset, u64 size) -> (u64 out_size, buffer<u8, 0x46, 0> out_buf) public ResultCode Read(ServiceCtx context) { - ulong position = context.Request.ReceiveBuff[0].Position; + ulong bufferAddress = context.Request.ReceiveBuff[0].Position; + ulong bufferLen = context.Request.ReceiveBuff[0].Size; ReadOption readOption = context.RequestData.ReadStruct<ReadOption>(); context.RequestData.BaseStream.Position += 4; @@ -27,15 +28,14 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy long offset = context.RequestData.ReadInt64(); long size = context.RequestData.ReadInt64(); - byte[] data = new byte[context.Request.ReceiveBuff[0].Size]; - - Result result = _baseFile.Get.Read(out long bytesRead, offset, new OutBuffer(data), size, readOption); - - context.Memory.Write(position, data); + using (var region = context.Memory.GetWritableRegion(bufferAddress, (int)bufferLen, true)) + { + Result result = _baseFile.Get.Read(out long bytesRead, offset, new OutBuffer(region.Memory.Span), size, readOption); - context.ResponseData.Write(bytesRead); + context.ResponseData.Write(bytesRead); - return (ResultCode)result.Value; + return (ResultCode)result.Value; + } } [CommandHipc(1)] |