From 71d76f6c7b65ccbc2aa70255e9da6039913d4692 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 19 May 2025 17:44:59 +0200 Subject: [PATCH] Reject NaN and Inf in check_v3d() too check_v2f() was already doing this --- src/script/common/c_converter.cpp | 3 +++ src/unittest/test_scriptapi.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 5b7331e47..a8c9ace3a 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -199,6 +199,9 @@ v3d check_v3d(lua_State *L, int index) double y = lua_tonumber(L, -2); double z = lua_tonumber(L, -1); lua_pop(L, 3); + CHECK_FLOAT(x, "x"); + CHECK_FLOAT(y, "y"); + CHECK_FLOAT(z, "z"); return v3d(x, y, z); } diff --git a/src/unittest/test_scriptapi.cpp b/src/unittest/test_scriptapi.cpp index 4fc03e6c5..0e407daf5 100644 --- a/src/unittest/test_scriptapi.cpp +++ b/src/unittest/test_scriptapi.cpp @@ -180,4 +180,17 @@ void TestScriptApi::testVectorReadMix(MyScriptApi *script) EXCEPTION_CHECK(LuaError, check_v3s16(L, -1)); lua_pop(L, 1); } + + // same but even the result is undefined + const char *errs2[] = { + "return {x=0, y=0, z=0/0}", // nan + "return {x=0, y=0, z=math.huge}", // inf + }; + for (auto &it : errs2) { + infostream << it << std::endl; + run(L, it, 1); + (void)read_v3s16(L, -1); + EXCEPTION_CHECK(LuaError, check_v3s16(L, -1)); + lua_pop(L, 1); + } }