Page MenuHomePhabricator

Lua parameter keys which are integers should be stringified if they have a magnitude > 2^53 - 1, not 2^53
Closed, DeclinedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Scribunto converts parameter keys which are numbers to strings if greater than 2^53 or less than -(2^53), since Lua cannot represent many integers beyond that point.
  • However, Lua is only capable of representing every integer between 2^53 - 1 and -(2^53) + 1. e.g. 2^53 == 2^53 + 1 evaluates to true.

What happens?:

  • Using 2^53 (9007199254740992) or -(2^53) (-9007199254740992) as a Scribunto parameter will result in a parameter key with the type number.

What should have happened instead?:

  • It should have the type string.

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

Change #1032079 had a related patch set uploaded (by Theknightwho; author: Theknightwho):

[mediawiki/extensions/Scribunto@master] Treat Scribunto max and min integers as 2^53 - 1 and -(2^53) + 1

https://gerrit.wikimedia.org/r/1032079

Just asking out of curiosity, how did you manage to find this limitation?

According to a quick search I did on IEEE 754, integers from -2^53 to 2^53 can be exactly represented. Would you happen to know why it is more restricted on Lua?

It seems to me that it should be possible to represent all powers of two up to the limit of the exponent, since the mantissa is just 1 for those numbers. So 2^53+1 is the lowest positive integer which needs to be rounded in order to fit in a double.

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> =2^53 - 1 - 2^53
-1
> =2^53 - 2^53
0
> =2^53 + 1 - 2^53
0

The commit message gives the example 2^53 == 2^53 + 1 that erroneously returns true, but it is because of the 2^53 + 1 expression, which for sure is exceeding.

Maybe the supported range is indeed the current [ -2^53; 2^53 ], and the change proposed here might be just wrong actually.

As this bug seems to be invalid, I suggest closing this ticket and the associated Gerrit change.