Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing QuickJS bug with nan value handling, causing an infinite loop on Nintendo Switch #366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexDenfordSkyboxLabs
Copy link

@AlexDenfordSkyboxLabs AlexDenfordSkyboxLabs commented Nov 14, 2024

The following scripting code was resulting in an infinite loop on Nintendo Switch in Minecraft with a custom behaviour pack:
image

The first while loop condition assumes that once it goes beyond the end of the array bounds, it returns undefined (which it does), but then it also assumes that comparing UNDEFINED to a real value, returns false (which it should, but doesn't).

This internal code in quick js relies on the C++ 'feature' that comparing any value against nan, returns false:
image

However, this is not a real constraint in the C++ stl/language.
https://stackoverflow.com/questions/38798791/nan-comparison-rule-in-c-c

It is a constraint for IEEE floating points, but C++ is not constrained to that requirement itself. So the result here is that on Switch sometimes it returns true for this evaluation, and in the scripting code above means we infinite loop.

Fix here is to deliberately and directly check for is nan and handle this case as false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant