caveman2cosmos / Caveman2Cosmos

The most expansive mod for Civilization IV: Beyond the Sword.
https://forums.civfanatics.com/forums/civ4-caveman-2-cosmos.449
59 stars 44 forks source link

Fixed a possible buffer overflow during culture decay #1442

Closed sp00n closed 1 year ago

sp00n commented 1 year ago

getCulture(ePlayerX) * (1000 - decayPermille) / 1000 could apparently trigger a buffer overflow if the plot culture is around 2,147,483 even though the value is divided by 1000 again. Reversing the order of operations to divide by 1000 first fixed this, but introduced another problem if the initial culture is lower than that, so we have to make an if else check. I've set the limit for reversing the order to 1 million.

Be aware I haven't tested the created DLL (it compiles fine) since I don't have a savegame for this version where this problem manifests, only for v43. I have tested a similarly adjusted code for v43, but there have been significant changes to CvPlot.cpp since then, which are incompatible with each other, so this requires evaluation.

dzfischer commented 1 year ago

Toffer fixed issue with https://github.com/caveman2cosmos/Caveman2Cosmos/commit/51d2971cd8d7b59f9625c37f43becb5ea18bc73d