diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 354fd3b823..9e139377c7 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -844,11 +844,13 @@ bool SavedataParam::GetExpectedHash(const std::string &dirPath, const std::strin void SavedataParam::LoadFile(const std::string& dirPath, const std::string& filename, PspUtilitySavedataFileData *fileData) { std::string filePath = dirPath + "/" + filename; - s64 readSize = -1; - if(!fileData->buf.IsValid()) + if (!fileData->buf.IsValid()) return; + u8 *buf = fileData->buf; - if(ReadPSPFile(filePath, &buf, fileData->bufSize, &readSize)) + u32 size = Memory::ValidSize(fileData->buf.ptr, fileData->bufSize); + s64 readSize = -1; + if (ReadPSPFile(filePath, &buf, size, &readSize)) fileData->size = readSize; } diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index 8f6b84bd7c..d5f20409bd 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -417,7 +417,7 @@ int ISOFileSystem::Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outd return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT; } else { int block = (u16)desc.firstLETableSector; - u32 size = (u32)desc.pathTableLength; + u32 size = Memory::ValidSize(outdataPtr, (u32)desc.pathTableLength); u8 *out = Memory::GetPointer(outdataPtr); int blocks = size / blockDevice->GetBlockSize(); diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 5ec060c436..9abfd60f51 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -1027,10 +1027,11 @@ static bool __IoRead(int &result, int id, u32 data_addr, int size, int &us) { return true; } else if (Memory::IsValidAddress(data_addr)) { CBreakPoints::ExecMemCheck(data_addr, true, size, currentMIPS->pc); - u8 *data = (u8*) Memory::GetPointer(data_addr); + u8 *data = (u8 *)Memory::GetPointer(data_addr); + u32 validSize = Memory::ValidSize(data_addr, size); if (f->npdrm) { - result = npdrmRead(f, data, size); - currentMIPS->InvalidateICache(data_addr, size); + result = npdrmRead(f, data, validSize); + currentMIPS->InvalidateICache(data_addr, validSize); return true; } @@ -1046,17 +1047,17 @@ static bool __IoRead(int &result, int id, u32 data_addr, int size, int &us) { AsyncIOEvent ev = IO_EVENT_READ; ev.handle = f->handle; ev.buf = data; - ev.bytes = size; + ev.bytes = validSize; ev.invalidateAddr = data_addr; ioManager.ScheduleOperation(ev); return false; } else { if (GetIOTimingMethod() != IOTIMING_REALISTIC) { - result = (int) pspFileSystem.ReadFile(f->handle, data, size); + result = (int)pspFileSystem.ReadFile(f->handle, data, validSize); } else { - result = (int) pspFileSystem.ReadFile(f->handle, data, size, us); + result = (int)pspFileSystem.ReadFile(f->handle, data, validSize, us); } - currentMIPS->InvalidateICache(data_addr, size); + currentMIPS->InvalidateICache(data_addr, validSize); return true; } } else { @@ -1136,12 +1137,13 @@ static bool __IoWrite(int &result, int id, u32 data_addr, int size, int &us) { } const void *data_ptr = Memory::GetPointer(data_addr); + const u32 validSize = Memory::ValidSize(data_addr, size); // Let's handle stdout/stderr specially. if (id == PSP_STDOUT || id == PSP_STDERR) { const char *str = (const char *) data_ptr; - const int str_size = size == 0 ? 0 : (str[size - 1] == '\n' ? size - 1 : size); + const int str_size = size <= 0 ? 0 : (str[validSize - 1] == '\n' ? validSize - 1 : validSize); INFO_LOG(SCEIO, "%s: %.*s", id == 1 ? "stdout" : "stderr", str_size, str); - result = size; + result = validSize; return true; } u32 error; @@ -1174,15 +1176,15 @@ static bool __IoWrite(int &result, int id, u32 data_addr, int size, int &us) { AsyncIOEvent ev = IO_EVENT_WRITE; ev.handle = f->handle; ev.buf = (u8 *) data_ptr; - ev.bytes = size; + ev.bytes = validSize; ev.invalidateAddr = 0; ioManager.ScheduleOperation(ev); return false; } else { if (GetIOTimingMethod() != IOTIMING_REALISTIC) { - result = (int) pspFileSystem.WriteFile(f->handle, (u8 *) data_ptr, size); + result = (int)pspFileSystem.WriteFile(f->handle, (u8 *) data_ptr, validSize); } else { - result = (int) pspFileSystem.WriteFile(f->handle, (u8 *) data_ptr, size, us); + result = (int)pspFileSystem.WriteFile(f->handle, (u8 *) data_ptr, validSize, us); } } return true;