discsys/psx - dont crash when reading absurdly negative LBAs

This commit is contained in:
zeromus 2015-09-17 18:18:06 -05:00
parent de85a6fdef
commit 6f049c2ab8
5 changed files with 28 additions and 7 deletions

View File

@ -201,10 +201,14 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
//todo - cache reader
DiscSystem.DiscSectorReader dsr = new DiscSystem.DiscSectorReader(Disc);
dsr.ReadLBA_2448(lba, SectorBuffer, 0);
Marshal.Copy(SectorBuffer, 0, new IntPtr(dst), 2448);
return OctoshockDll.SHOCK_OK;
int readed = dsr.ReadLBA_2448(lba, SectorBuffer, 0);
if (readed == 2448)
{
Marshal.Copy(SectorBuffer, 0, new IntPtr(dst), 2448);
return OctoshockDll.SHOCK_OK;
}
else
return OctoshockDll.SHOCK_ERROR;
}
}

View File

@ -87,6 +87,8 @@ namespace BizHawk.Emulation.DiscSystem
{
var sector = disc.SynthProvider.Get(lba);
if (sector == null) return 0;
PrepareBuffer(buffer, offset, 2352);
PrepareJob(lba);
job.DestBuffer2448 = buf2442;
@ -110,6 +112,8 @@ namespace BizHawk.Emulation.DiscSystem
public int ReadLBA_2448(int lba, byte[] buffer, int offset)
{
var sector = disc.SynthProvider.Get(lba);
if (sector == null) return 0;
PrepareBuffer(buffer, offset, 2352);
PrepareJob(lba);
@ -122,7 +126,7 @@ namespace BizHawk.Emulation.DiscSystem
sector.Synth(job);
//we went straight to the caller's buffer, so no need to copy
return 2442;
return 2448;
}
int ReadLBA_2048_Mode1(int lba, byte[] buffer, int offset)
@ -130,6 +134,8 @@ namespace BizHawk.Emulation.DiscSystem
//we can read the 2048 bytes directly
var sector = disc.SynthProvider.Get(lba);
if (sector == null) return 0;
PrepareBuffer(buffer, offset, 2048);
PrepareJob(lba);
job.DestBuffer2448 = buf2442;
@ -147,6 +153,8 @@ namespace BizHawk.Emulation.DiscSystem
//we can read the 2048 bytes directly but we have to get them from the mode 2 data
var sector = disc.SynthProvider.Get(lba);
if (sector == null) return 0;
PrepareBuffer(buffer, offset, 2048);
PrepareJob(lba);
job.DestBuffer2448 = buf2442;
@ -167,6 +175,8 @@ namespace BizHawk.Emulation.DiscSystem
{
var sector = disc.SynthProvider.Get(lba);
if (sector == null) return 0;
PrepareBuffer(buffer, offset, 12);
PrepareJob(lba);
job.DestBuffer2448 = buf2442;
@ -198,6 +208,8 @@ namespace BizHawk.Emulation.DiscSystem
//in no case do we need the ECC so build special flags here
var sector = disc.SynthProvider.Get(lba);
if (sector == null) return 0;
PrepareBuffer(buffer, offset, 2048);
PrepareJob(lba);
job.DestBuffer2448 = buf2442;
@ -273,6 +285,8 @@ namespace BizHawk.Emulation.DiscSystem
{
var sector = disc.SynthProvider.Get(lba);
if (sector == null) return 0;
PrepareJob(lba);
job.DestBuffer2448 = buf2442;
job.DestOffset = 0;

View File

@ -133,6 +133,8 @@ namespace BizHawk.Emulation.DiscSystem
public ISectorSynthJob2448 Get(int lba)
{
int index = lba - FirstLBA;
if (index < 0) return null;
if (index >= Sectors.Count) return null;
return Sectors[index];
}
}

Binary file not shown.

View File

@ -2415,11 +2415,12 @@ Breakout:
bool ShockDiscRef::ReadLBA_PW(uint8* pwbuf96, int32 lba, bool hint_fullread)
{
//TODO - whats that hint mean
//TODO - should return false if out of range totally
//reference: static const int32 LBA_Read_Minimum = -150;
//reference: static const int32 LBA_Read_Maximum = 449849; // 100 * 75 * 60 - 150 - 1
u8 tmp[2448];
ReadLBA2448(lba,tmp);
s32 ret = ReadLBA2448(lba,tmp);
if(ret != SHOCK_OK)
return false;
memcpy(pwbuf96,tmp+2352,96);
return true;
}