Skip to content

Commit

Permalink
Merge pull request jgilje#18 from TTKMedia/master
Browse files Browse the repository at this point in the history
Player crash fixes
  • Loading branch information
jgilje committed May 12, 2022
2 parents dba4b35 + fd280a4 commit c797efd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/v2mconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ static ssbase readfile(const unsigned char *inptr, const int inlen)
ssbase base;
memset(&base, 0, sizeof(base));

if (inlen < 12) return base;

base.timediv = (*((uint32_t*)(d)));
base.timediv2 = 10000*base.timediv;
base.maxtime = *((uint32_t*)(d + 4));
base.gdnum = *((uint32_t*)(d + 8));

d += 12;
base.gptr = d;

if (inlen - 12 < 10*base.gdnum) return base;
d += 10*base.gdnum;

for (int ch = 0; ch < 16; ch++)
{
ssbase::_basech &c = base.chan[ch];
Expand Down Expand Up @@ -73,14 +79,10 @@ static ssbase readfile(const unsigned char *inptr, const int inlen)
base.spsize = *((uint32_t*)d);
d += 4;
base.speechdata = d;
if (base.spsize > inlen - (d - inptr))
{
base.spsize = inlen - (d - inptr);
}
d += base.spsize;

// small sanity check
if (base.spsize < 0 || base.spsize > 8192)
if (base.spsize < 0 || base.spsize > 8192 || (d - inptr) > inlen)
{
base.spsize = 0;
base.speechdata = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/v2mplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void V2MPlayer::Reset()
m_state.beat = 0;
m_state.tick = 0;
m_state.smplrem = 0;
m_state.cursmpl = 0;

if (m_samplerate)
{
Expand Down Expand Up @@ -309,6 +310,7 @@ void V2MPlayer::Play(uint32_t a_time)
m_state.smpldelta = -1;
}

m_state.cursmpl = cursmpl;
m_state.smpldelta -= (destsmpl - cursmpl);
m_fadeval = 1.0f;
m_fadedelta = 0.0f;
Expand Down
8 changes: 5 additions & 3 deletions src/v2mplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ class V2MPlayer
reinterpret_cast<V2MPlayer*>(a_this)->Render(a_buffer, a_len);
}

bool NoEnd();
uint32_t Length();
bool NoEnd();

// returns if song is currently playing
// returns song length
uint32_t Length();

// returns if song is currently playing
bool IsPlaying();

#ifdef V2MPLAYER_SYNC_FUNCTIONS
Expand Down

0 comments on commit c797efd

Please sign in to comment.