From 0078554d6a9df92ce25e07706c4e51143151b2c8 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 10 Jan 2021 15:10:03 +0100 Subject: [PATCH] Fix: GetCargoTranslation could return out-of-bounds index for old-style NewGRF using cargo-slots. --- src/newgrf_cargo.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/newgrf_cargo.cpp b/src/newgrf_cargo.cpp index 22c7120d82..c2859b71ef 100644 --- a/src/newgrf_cargo.cpp +++ b/src/newgrf_cargo.cpp @@ -91,7 +91,10 @@ uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit) { /* Pre-version 7 uses the 'climate dependent' ID in callbacks and properties, i.e. cargo is the cargo ID */ - if (grffile->grf_version < 7 && !usebit) return cargo; + if (grffile->grf_version < 7 && !usebit) { + if (cargo >= CargoSpec::GetArraySize() || !CargoSpec::Get(cargo)->IsValid()) return CT_INVALID; + return cargo; + } /* Other cases use (possibly translated) cargobits */