os.date() appends null terminator (\0) to ISO 8601 UTC timestamp in sandboxed Lua 5.4
What happened?
Starting from FXServer 12767, using os.date("!%Y-%m-%dT%H:%M:%SZ", os.time()) with UTC formatting appends a null terminator (<\0>) at the end of the string.
Expected result
os.date("!%Y-%m-%dT%H:%M:%SZ", os.time()) should return a valid ISO 8601 timestamp without a null terminator (<\0>).
Reproduction steps
- Run the following Lua script on FXServer 12767+:
print("ISO 8601 (UTC):", os.date("!%Y-%m-%dT%H:%M:%SZ")) print("ISO 8601 (LOCAL):", os.date("%Y-%m-%dT%H:%M:%SZ")) print("Standard Date:", os.date("%c")) print("YYYY-MM-DD:", os.date("%Y-%m-%d")) print("24-hour Time:", os.date("%H:%M:%S")) print("12-hour Time:", os.date("%I:%M:%S %p")) print("Day of the Week:", os.date("%A")) print("Day of the Year:", os.date("%j")) - Observe the output (Bug):
ISO 8601 (UTC): 2025-02-11T07:34:57Z<\0> ISO 8601 (LOCAL): 2025-02-11T14:34:57Z Standard Date: Tue Feb 11 14:34:57 2025 YYYY-MM-DD: 2025-02-11 24-hour Time: 14:34:57 12-hour Time: 02:34:57 PM Day of the Week: Tuesday Day of the Year: 042 - This issue occurs in sandboxed Lua 5.4 and affects timestamps formatted in ISO 8601 (
!%Y-%m-%dT%H:%M:%SZ), causing an unexpected null terminator (<\0>) at the end of the string.
Importancy
There's a workaround
Area(s)
FXServer
Specific version(s)
Server 12767 windows
Additional information
This issue was introduced by commit: 76d4fc0
I have the same issue using the new versions of the artifacts.
Definitely not a fix, but it should help if you are unable to downgrade artifacts for any reason:
local timestamp = os.date("!%Y-%m-%dT%H:%M:%S.000Z")
timestamp = timestamp:gsub(string.char(0), "")
A quick workaround is to use:
os.date('!%Y-%m-%dT%H:%M:%SZ'):gsub('%z', '')
This removes the null terminator (\0) appended to the ISO 8601 UTC timestamp. Hopefully, a more permanent fix will be available soon, but this should help in the meantime.
Fixed in https://github.com/citizenfx/fivem/commit/d61273dadb1c9307d2255484e4cbf2b99e2d67eb