1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59: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:
Misa 2020-08-14 02:02:16 -07:00 committed by Ethan Lee
parent e481c75404
commit 4bfd9de371
2 changed files with 11 additions and 6 deletions

View file

@ -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];
};

View file

@ -80,12 +80,15 @@ void musicclass::init()
#define FOREACH_TRACK(track_name) \
index = musicReadBlob.getIndex(track_name); \
if (index >= 0 && index < musicReadBlob.max_headers) \
{ \
rw = SDL_RWFromMem(musicReadBlob.getAddress(index), musicReadBlob.getSize(index)); \
musicTracks.push_back(MusicTrack( rw ));
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++)