diff options
author | frosch <frosch@openttd.org> | 2021-01-10 15:10:03 +0100 |
---|---|---|
committer | frosch <github@elsenhans.name> | 2021-01-10 21:24:38 +0100 |
commit | 0078554d6a9df92ce25e07706c4e51143151b2c8 (patch) | |
tree | bf8daae6d1a6ad8d3b4944c308852f85adcc7264 /src | |
parent | 63288f80f3970905bc9b18e0961eec3da5be7ee2 (diff) | |
download | openttd-0078554d6a9df92ce25e07706c4e51143151b2c8.tar.xz |
Fix: GetCargoTranslation could return out-of-bounds index for old-style NewGRF using cargo-slots.
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf_cargo.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/newgrf_cargo.cpp b/src/newgrf_cargo.cpp index 22c7120d8..c2859b71e 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 */ |