prevent crash when TD6s have less than 4 bytes

This commit is contained in:
Ted John 2016-05-05 21:41:46 +01:00
parent 70d613ede2
commit a76a76a4b5
1 changed files with 6 additions and 0 deletions

View File

@ -79,6 +79,12 @@ rct_track_td6 *track_design_open(const utf8 *path)
if (file != NULL) {
// Read whole file into a buffer
size_t bufferLength = (size_t)SDL_RWsize(file);
if (bufferLength < 4) {
log_error("Invalid track file: %s.", path);
SDL_RWclose(file);
return false;
}
uint8 *buffer = (uint8*)malloc(bufferLength);
if (buffer == NULL) {
log_error("Unable to allocate memory for track design file.");