Skip to content

Commit c797efd

Browse files
authored
Merge pull request jgilje#18 from TTKMedia/master
Player crash fixes
2 parents dba4b35 + fd280a4 commit c797efd

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/v2mconv.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@ static ssbase readfile(const unsigned char *inptr, const int inlen)
2222
ssbase base;
2323
memset(&base, 0, sizeof(base));
2424

25+
if (inlen < 12) return base;
26+
2527
base.timediv = (*((uint32_t*)(d)));
2628
base.timediv2 = 10000*base.timediv;
2729
base.maxtime = *((uint32_t*)(d + 4));
2830
base.gdnum = *((uint32_t*)(d + 8));
31+
2932
d += 12;
3033
base.gptr = d;
34+
35+
if (inlen - 12 < 10*base.gdnum) return base;
3136
d += 10*base.gdnum;
37+
3238
for (int ch = 0; ch < 16; ch++)
3339
{
3440
ssbase::_basech &c = base.chan[ch];
@@ -73,14 +79,10 @@ static ssbase readfile(const unsigned char *inptr, const int inlen)
7379
base.spsize = *((uint32_t*)d);
7480
d += 4;
7581
base.speechdata = d;
76-
if (base.spsize > inlen - (d - inptr))
77-
{
78-
base.spsize = inlen - (d - inptr);
79-
}
8082
d += base.spsize;
8183

8284
// small sanity check
83-
if (base.spsize < 0 || base.spsize > 8192)
85+
if (base.spsize < 0 || base.spsize > 8192 || (d - inptr) > inlen)
8486
{
8587
base.spsize = 0;
8688
base.speechdata = 0;

src/v2mplayer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ void V2MPlayer::Reset()
148148
m_state.beat = 0;
149149
m_state.tick = 0;
150150
m_state.smplrem = 0;
151+
m_state.cursmpl = 0;
151152

152153
if (m_samplerate)
153154
{
@@ -309,6 +310,7 @@ void V2MPlayer::Play(uint32_t a_time)
309310
m_state.smpldelta = -1;
310311
}
311312

313+
m_state.cursmpl = cursmpl;
312314
m_state.smpldelta -= (destsmpl - cursmpl);
313315
m_fadeval = 1.0f;
314316
m_fadedelta = 0.0f;

src/v2mplayer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ class V2MPlayer
7676
reinterpret_cast<V2MPlayer*>(a_this)->Render(a_buffer, a_len);
7777
}
7878

79-
bool NoEnd();
80-
uint32_t Length();
79+
bool NoEnd();
8180

82-
// returns if song is currently playing
81+
// returns song length
82+
uint32_t Length();
83+
84+
// returns if song is currently playing
8385
bool IsPlaying();
8486

8587
#ifdef V2MPLAYER_SYNC_FUNCTIONS

0 commit comments

Comments
 (0)