The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: victor_18993 on August 22, 2026, 12:24:38 PM

Title: Several memory-safety issues fixed in trunk (r12186–r12189)
Post by: victor_18993 on August 22, 2026, 12:24:38 PM
During a recent code audit, several long-standing memory-safety issues were identified and have now been fixed in trunk:

- r12186 — fixed out-of-bounds reads/writes in locality_factor_per_year. In some configurations this could corrupt factory worker settings.
- r12187 — fixed out-of-bounds reads/writes in startingmoneyperyear. This could corrupt city-road configuration and produce incorrect starting-money calculations.
- r12189 — fixed a Windows use-after-scope in dr_mkdir(). The affected path was reached during every Windows startup when creating the maps, save and screenshot directories.

The fixes are deliberately small and do not change savegame, network or pak formats.

Current regression suite remains green (287/287).

These were mostly silent defects: the game could continue running while using corrupted or undefined state, which made them particularly difficult to diagnose from their visible symptoms.
Title: Re: Several memory-safety issues fixed in trunk (r12186–r12189)
Post by: victor_18993 on August 22, 2026, 01:54:12 PM
A small update from the image-loading audit:

Two more long-standing issues have now been fixed in trunk:

- r12190 — read_bmp() now checks that the BMP file was successfully opened before reading it.
- r12191 — the same issue was fixed in read_ppm().

In both cases the file had already been opened successfully once during format detection, but the reader opened it again without checking the second result. If that second open failed, a NULL FILE* could reach the C runtime. On Windows/MSVC this can terminate the process.

Both fixes are very small and valid BMP/PPM output remains byte-identical. The full regression suite is still green (287/287), with no savegame, network or pak format changes.

All three image readers now correctly check their file opens.

While reviewing read_ppm(), one additional small resource leak was found on the truncated-file error path. I will handle that separately rather than mixing it into this fix.