1
0
Fork 0

Fix: Crash/Undefined behaviour in station view window. (#14183)

No column limit was applied when drawing waiting cargo, which could cause out-of-bounds array access.
pull/14189/head
Peter Nelson 2025-05-02 08:02:35 +01:00 committed by GitHub
parent e0a9c7d818
commit 932dca927b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 2 deletions

View File

@ -1759,6 +1759,7 @@ struct StationViewWindow : public Window {
*/
StringID SearchNonStop(CargoDataEntry &cd, StationID station, int column)
{
assert(column < NUM_COLUMNS);
CargoDataEntry *parent = cd.GetParent();
for (int i = column - 1; i > 0; --i) {
if (this->groupings[i] == GR_DESTINATION) {
@ -1771,7 +1772,7 @@ struct StationViewWindow : public Window {
parent = parent->GetParent();
}
if (this->groupings[column + 1] == GR_DESTINATION) {
if (column < NUM_COLUMNS - 1 && this->groupings[column + 1] == GR_DESTINATION) {
CargoDataSet::iterator begin = cd.Begin();
CargoDataSet::iterator end = cd.End();
if (begin != end && ++(cd.Begin()) == end && (*(begin))->GetStation() == station) {
@ -1796,6 +1797,7 @@ struct StationViewWindow : public Window {
*/
int DrawEntries(CargoDataEntry &entry, const Rect &r, int pos, int maxrows, int column, CargoType cargo = INVALID_CARGO)
{
assert(column < NUM_COLUMNS);
if (this->sortings[column] == CargoSortType::AsGrouping) {
if (this->groupings[column] != GR_CARGO) {
entry.Resort(CargoSortType::StationString, this->sort_orders[column]);
@ -1855,7 +1857,7 @@ struct StationViewWindow : public Window {
this->SetDisplayedRow(cd);
}
--pos;
if (auto_distributed || column == 0) {
if ((auto_distributed || column == 0) && column < NUM_COLUMNS - 1) {
pos = this->DrawEntries(cd, r, pos, maxrows, column + 1, cargo);
}
}