Skip to content

Commit d115188

Browse files
committed
fix some memory access errors
1 parent 9f376fb commit d115188

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

emu/cores/vsu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "../EmuStructs.h"
55

66

7-
#define OPT_VST_WRAM_WRT_WHILE_ON 0x0001 // allow writes to waveRAM while sound is on (buggy emulation)
7+
#define OPT_VSU_WRAM_WRT_WHILE_ON 0x0001 // allow writes to waveRAM while sound is on (buggy emulation)
88

99

1010
extern const DEV_DECL sndDev_VBoyVSU;

player/dblk_compr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ void ReadPCMComprTable(UINT32 dataSize, const UINT8* data, PCM_COMPR_TBL* comprT
729729
UINT8 valSize;
730730
UINT32 tblSize;
731731

732+
if (dataSize < 0x06)
733+
return; // don't try to access elements when there is no data
734+
732735
comprTbl->comprType = data[0x00];
733736
comprTbl->cmpSubType = data[0x01];
734737
comprTbl->bitsDec = data[0x02];

player/vgmplayer_cmdhandler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ void VGMPlayer::Cmd_DataBlock(void)
724724

725725
pcmBnk->bankOfs.push_back(oldLen);
726726
pcmBnk->bankSize.push_back(dataLen);
727+
if (!dataLen)
728+
return; // don't try to access std::vector elements when there is no data
727729

728730
pcmBnk->data.resize(oldLen + dataLen);
729731
if (dblkType & 0x40)
@@ -751,6 +753,8 @@ void VGMPlayer::Cmd_DataBlock(void)
751753
if (cDev == NULL)
752754
break;
753755

756+
if (dblkLen < 0x08)
757+
return;
754758
memSize = ReadLE32(&fData[0x00]);
755759
dataOfs = ReadLE32(&fData[0x04]);
756760
dataPtr = &fData[0x08];
@@ -780,13 +784,17 @@ void VGMPlayer::Cmd_DataBlock(void)
780784

781785
if (! (dblkType & 0x20))
782786
{
787+
if (dblkLen < 0x02)
788+
return;
783789
// C0..DF: 16-bit addressing
784790
dataOfs = ReadLE16(&fData[0x00]);
785791
dataLen = dblkLen - 0x02;
786792
dataPtr = &fData[0x02];
787793
}
788794
else
789795
{
796+
if (dblkLen < 0x04)
797+
return;
790798
// E0..FF: 32-bit addressing
791799
dataOfs = ReadLE32(&fData[0x00]);
792800
dataLen = dblkLen - 0x04;

0 commit comments

Comments
 (0)