dyne / Zenroom

Embedded no-code VM executing human-like language to manipulate data and process cryptographic operations.
https://dev.zenroom.org
GNU Affero General Public License v3.0
195 stars 62 forks source link

Time parsing 32bit corner-case #846

Open matteo-cristino opened 5 months ago

matteo-cristino commented 5 months ago

Since time is an integer, it could take values from -2147483648 to 2147483647, but if I try to do

TIME.new(-2147483648)

the following error is returned

Could not read unix timestamp -2.147484e+09

While this error is not returned in the case I use

TIME.new("-2147483648")

This seems due to some conversion from number to string done internally in lua since, as stated in the documentation, both number and strings are seen as string from lua_isstring function (making also the lua_isnumber branching useless)

https://github.com/dyne/Zenroom/blob/ca02f6cace9ecc456d970a62dcd388ebafe20730/src/zen_time.c#L74-L121

and thus they both pass thorugh the lua_tostring function. I tried also to move the branch with lua_isnumber before the lua_isstring one, but it seemed that after a certain number, lua was not able to read them correctly.

Thus at the moment, if we use numbers in input we are only loosing the time -2147483648 and using strings in input we should not lose anything. Anyway interesting to notice and maybe look further into it in case any other problems with numbers came up.