(svn r27278) -Fix: Handle savegames with an unexpected amount of industry-builder or NewGRF entity-mapping more gracefully.

This commit is contained in:
frosch 2015-05-09 10:04:50 +00:00
parent 5e47c27550
commit 3f55e5364e
3 changed files with 7 additions and 7 deletions

View File

@ -160,14 +160,12 @@ static void Save_ITBL()
/** Load industry-type build data. */ /** Load industry-type build data. */
static void Load_ITBL() static void Load_ITBL()
{ {
_industry_builder.Reset();
int index; int index;
for (int i = 0; i < NUM_INDUSTRYTYPES; i++) { while ((index = SlIterateArray()) != -1) {
index = SlIterateArray(); if ((uint)index >= NUM_INDUSTRYTYPES) SlErrorCorrupt("Too many industry builder datas");
assert(index == i); SlObject(_industry_builder.builddata + index, _industrytype_builder_desc);
SlObject(_industry_builder.builddata + i, _industrytype_builder_desc);
} }
index = SlIterateArray();
assert(index == -1);
} }
extern const ChunkHandler _industry_chunk_handlers[] = { extern const ChunkHandler _industry_chunk_handlers[] = {

View File

@ -51,7 +51,7 @@ void Load_NewGRFMapping(OverrideManagerBase &mapping)
int index; int index;
while ((index = SlIterateArray()) != -1) { while ((index = SlIterateArray()) != -1) {
if ((uint)index >= max_id) break; if ((uint)index >= max_id) SlErrorCorrupt("Too many NewGRF entity mappings");
SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc); SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc);
} }
} }

View File

@ -1667,9 +1667,11 @@ static void SlLoadChunk(const ChunkHandler *ch)
case CH_ARRAY: case CH_ARRAY:
_sl.array_index = 0; _sl.array_index = 0;
ch->load_proc(); ch->load_proc();
if (_next_offs != 0) SlErrorCorrupt("Invalid array length");
break; break;
case CH_SPARSE_ARRAY: case CH_SPARSE_ARRAY:
ch->load_proc(); ch->load_proc();
if (_next_offs != 0) SlErrorCorrupt("Invalid array length");
break; break;
default: default:
if ((m & 0xF) == CH_RIFF) { if ((m & 0xF) == CH_RIFF) {