opentibiabr / canary

Canary Server 13.x for OpenTibia community.
https://docs.opentibiabr.com/
GNU General Public License v2.0
376 stars 625 forks source link

possible crash: CONDITION_LIGHT division by zero #3047

Closed Zbizu closed 1 day ago

Zbizu commented 3 days ago

Priority

Low

Area

What happened?

Summary

I just discovered a very old bug that is present in ALL tfs-based engines, which means that Canary could be affected too a little fun fact: OTServ doesn't have this bug (it was fixed somewhere around 2012 or earlier)

Steps to reproduce

  1. change light level to 0 in utevo lux
  2. cast spell

Observed result

division by zero (server crash)

note: this screenshot was taken while debugging my own engine, but I've checked your code and it seems to have same bug obraz

Line causing this

https://github.com/opentibiabr/canary/blob/main/src/creatures/combat/condition.cpp#L2508

possibly also: https://github.com/opentibiabr/canary/blob/main/src/creatures/combat/condition.cpp#L2543

Solution

set minimum light level to 1 in the line I linked

What OS are you seeing the problem on?

Linux

Code of Conduct

dudantas commented 2 days ago

You are correct, every division must ensure that the value is not divided by zero, as this results in undefined behavior in C++ and can cause program crashes. To address this, I recommend adding a check to ensure the divisor is not zero before performing the division. If you'd like, you could open a pull request with this fix to help improve the project.