Wuzzy/Shadow_Forest
1
1
Fork
You've already forked Shadow_Forest
3

Fix crash on punch call in Luanti 5.16 #42

Merged
Wuzzy merged 1 commit from JacobK/Shadow_Forest:master into master 2026年06月08日 17:17:19 +02:00
Contributor
Copy link

I am using Trisquel 11.0.1, but a friend reported that this issue also happens on Windows, and we actually discovered the issue in a different game (that uses code from Shadow Forest) on a Debian machine. Since the issue depends on the Luanti version, I used ROllerozxa's AppImage builds [1] to figure out which versions were affected. I found that versions 5.16.0 and 5.16.1 crash, but 5.15.2 does not. I tested this pull request on all 3 of those versions as well as a local build of 5.8.0.

The crash happens when the player shoots a shadow monster with the Staff of Light, or when a shadow monster attacks the player. I am not sure exactly why the crash happens, but it seems to have something to do with math.huge, as replacing instances of that with nil fixes the crash. This pull request simply replaces math.huge in both calls to punch. There are 2 other uses of math.huge in Shadow Forest, but those don't seem to cause a problem.

I am not very familiar with punch calls, but based on my understanding, the number used here should not affect damage amount, because full_punch_interval is always 0.0 (except for the melee weapons which don't use the affected punch calls). lua_api.md does not describe what passing nil actually does, but my guess is that it's like the previous use of math.huge, which is to just do full damage here.

[1] https://github.com/rollerozxa/luanti-appimage/

I am using Trisquel 11.0.1, but a friend reported that this issue also happens on Windows, and we actually discovered the issue in a different game (that uses code from Shadow Forest) on a Debian machine. Since the issue depends on the Luanti version, I used ROllerozxa's AppImage builds [1] to figure out which versions were affected. I found that versions 5.16.0 and 5.16.1 crash, but 5.15.2 does not. I tested this pull request on all 3 of those versions as well as a local build of 5.8.0. The crash happens when the player shoots a shadow monster with the Staff of Light, or when a shadow monster attacks the player. I am not sure exactly why the crash happens, but it seems to have something to do with math.huge, as replacing instances of that with nil fixes the crash. This pull request simply replaces math.huge in both calls to punch. There are 2 other uses of math.huge in Shadow Forest, but those don't seem to cause a problem. I am not very familiar with punch calls, but based on my understanding, the number used here should not affect damage amount, because full_punch_interval is always 0.0 (except for the melee weapons which don't use the affected punch calls). lua_api.md does not describe what passing nil actually does, but my guess is that it's like the previous use of math.huge, which is to just do full damage here. [1] https://github.com/rollerozxa/luanti-appimage/
Author
Contributor
Copy link

With the help of git bisect, I found that the Luanti commit that introduced the crash is 74e3c1c2111775988ae3af01af44cb1b23660dbb ("Fix readParam not rejecting nan/inf (#16918)"). The pull request description even mentions your use case:

Someone could try to use Inf with time_from_last_punch (core.get_hit_params() and ObjectRef:punch()) or core.get_objects_inside_radius(): radius, but I don't think that's reasonable or likely.

With the help of `git bisect`, I found that the Luanti commit that introduced the crash is 74e3c1c2111775988ae3af01af44cb1b23660dbb ("Fix readParam<float> not rejecting nan/inf ([#16918](https://github.com/luanti-org/luanti/pull/16918))"). The pull request description even mentions your use case: > Someone could try to use Inf with time_from_last_punch (core.get_hit_params() and ObjectRef:punch()) or core.get_objects_inside_radius(): radius, but I don't think that's reasonable or likely.
Owner
Copy link

Nice find! I can confirm the crash in 5.16.1.
I wrote that code when it was not yet officially "illegal" to use math.huge as arguments for most API functions.

Ironically, it was I who later added this text to lua_api.txt:

NaN, positive infinity and negative infinity should not be
assumed to be supported unless mentioned explicitly.

Nice find! I can confirm the crash in 5.16.1. I wrote that code when it was not yet officially "illegal" to use `math.huge` as arguments for most API functions. Ironically, it was I who later added this text to `lua_api.txt`: > NaN, positive infinity and negative infinity should not be assumed to be supported unless mentioned explicitly.
Owner
Copy link

Bugfix confirmed working. Indeed the nil appears to mean "apply full damage" (I tested it in a dummy mod). Thankfully, support for a nil argument existed for a very long time (even in 5.0.0).

I also did a little cleanup afterwards. The _last_punch variable of the shadow mob is now useless, so I deleted it.

And yes, the other uses of math.huge seem harmless to me as well as those don’t touch the Lua API.

Thank you for this bug report and bugfix! 👍

Bugfix confirmed working. Indeed the `nil` appears to mean "apply full damage" (I tested it in a dummy mod). Thankfully, support for a `nil` argument existed for a very long time (even in 5.0.0). I also did a little cleanup afterwards. The `_last_punch` variable of the shadow mob is now useless, so I deleted it. And yes, the other uses of `math.huge` seem harmless to me as well as those don’t touch the Lua API. Thank you for this bug report and bugfix! :+1:
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Wuzzy/Shadow_Forest!42
Reference in a new issue
Wuzzy/Shadow_Forest
No description provided.
Delete branch "JacobK/Shadow_Forest:master"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?