mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-27 23:40:39 +00:00
Merge pull request #7058 from unknownbrackets/io-minor
Handle negative read sizes more correctly
This commit is contained in:
commit
517ca0569e
@ -566,28 +566,30 @@ size_t ISOFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size)
|
||||
|
||||
_dbg_assert_msg_(FILESYS, (middleSize & 2047) == 0, "Remaining size should be aligned");
|
||||
|
||||
if (firstBlockSize != 0)
|
||||
const u8 *const start = pointer;
|
||||
if (firstBlockSize > 0)
|
||||
{
|
||||
blockDevice->ReadBlock(secNum++, theSector);
|
||||
memcpy(pointer, theSector + firstBlockOffset, firstBlockSize);
|
||||
pointer += firstBlockSize;
|
||||
}
|
||||
if (middleSize != 0)
|
||||
if (middleSize > 0)
|
||||
{
|
||||
const u32 sectors = (u32)(middleSize / 2048);
|
||||
blockDevice->ReadBlocks(secNum, sectors, pointer);
|
||||
secNum += sectors;
|
||||
pointer += middleSize;
|
||||
}
|
||||
if (lastBlockSize != 0)
|
||||
if (lastBlockSize > 0)
|
||||
{
|
||||
blockDevice->ReadBlock(secNum++, theSector);
|
||||
memcpy(pointer, theSector, lastBlockSize);
|
||||
pointer += lastBlockSize;
|
||||
}
|
||||
|
||||
e.seekPos += (unsigned int)size;
|
||||
return (size_t)size;
|
||||
size_t totalBytes = pointer - start;
|
||||
e.seekPos += (unsigned int)totalBytes;
|
||||
return (size_t)totalBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -726,6 +726,9 @@ bool __IoRead(int &result, int id, u32 data_addr, int size) {
|
||||
if (!(f->openMode & FILEACCESS_READ)) {
|
||||
result = ERROR_KERNEL_BAD_FILE_DESCRIPTOR;
|
||||
return true;
|
||||
} else if (size < 0) {
|
||||
result = SCE_KERNEL_ERROR_ILLEGAL_ADDR;
|
||||
return true;
|
||||
} else if (Memory::IsValidAddress(data_addr)) {
|
||||
CBreakPoints::ExecMemCheck(data_addr, true, size, currentMIPS->pc);
|
||||
u8 *data = (u8*) Memory::GetPointer(data_addr);
|
||||
@ -857,6 +860,10 @@ bool __IoWrite(int &result, int id, u32 data_addr, int size) {
|
||||
result = ERROR_KERNEL_BAD_FILE_DESCRIPTOR;
|
||||
return true;
|
||||
}
|
||||
if (size < 0) {
|
||||
result = SCE_KERNEL_ERROR_ILLEGAL_ADDR;
|
||||
return true;
|
||||
}
|
||||
|
||||
CBreakPoints::ExecMemCheck(data_addr, false, size, currentMIPS->pc);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user