mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +01:00
Check index of tracks in musicclass::init()
It's possible that musicReadBlob.getIndex() could return the sentinel value of -1 in case the header with that name is invalid, in which case we should simply not do anything. Otherwise it'll lead to segfaults. I opted to do the full bounds check just to be safe, too. For further safety, I hardcoded the max number of headers, 128, less, so 128 is copy-pasted less and in the future if it needs to be changed it'll only have to be changed in one place.
This commit is contained in:
parent
e481c75404
commit
4bfd9de371
2 changed files with 11 additions and 6 deletions
|
@ -55,10 +55,12 @@ public:
|
|||
|
||||
void clear();
|
||||
|
||||
static const int max_headers = 128;
|
||||
|
||||
private:
|
||||
int numberofHeaders;
|
||||
resourceheader m_headers[128];
|
||||
char* m_memblocks[128];
|
||||
resourceheader m_headers[max_headers];
|
||||
char* m_memblocks[max_headers];
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -80,12 +80,15 @@ void musicclass::init()
|
|||
|
||||
#define FOREACH_TRACK(track_name) \
|
||||
index = musicReadBlob.getIndex(track_name); \
|
||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index)); \
|
||||
musicTracks.push_back(MusicTrack( rw ));
|
||||
if (index >= 0 && index < musicReadBlob.max_headers) \
|
||||
{ \
|
||||
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index)); \
|
||||
musicTracks.push_back(MusicTrack( rw )); \
|
||||
}
|
||||
|
||||
TRACK_NAMES
|
||||
|
||||
num_mmmmmm_tracks += 16;
|
||||
num_mmmmmm_tracks += musicTracks.size();
|
||||
|
||||
const std::vector<int> extra = musicReadBlob.getExtra();
|
||||
for (size_t i = 0; i < extra.size(); i++)
|
||||
|
@ -108,7 +111,7 @@ void musicclass::init()
|
|||
|
||||
#undef FOREACH_TRACK
|
||||
|
||||
num_pppppp_tracks += 16;
|
||||
num_pppppp_tracks += musicTracks.size() - num_mmmmmm_tracks;
|
||||
|
||||
const std::vector<int> extra = musicReadBlob.getExtra();
|
||||
for (size_t i = 0; i < extra.size(); i++)
|
||||
|
|
Loading…
Reference in a new issue