[SERVER-8744] NumberInt overflow handling is different in V8 and Spidermonkey Created: 26/Feb/13  Updated: 31/Aug/15  Resolved: 13/Aug/15

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: None
Fix Version/s: 3.1.7

Type: Bug Priority: Minor - P4
Reporter: Shaun Verch Assignee: Jonathan Reams
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-10965 Would like Min/Max value constants fo... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Build 7 08/10/15, Build 8 08/31/15
Participants:

 Description   

Actual Test                         | SM                                       | V8        
____________________________________|__________________________________________|_________________________________________
NumberLong("18446744073709551616")  | Tue Feb 26 13:45:55.895 Error: could not convert string to long long (shell eval):1 | Tue Feb 26 13:45:55.863 Error: could not convert "18446744073709551616" to NumberLong (shell eval):1
NumberLong(18446744073709551616)    | NumberLong("-9223372036854775808")       | NumberLong("-9223372036854775808")
NumberLong("-18446744073709551616") | Tue Feb 26 13:45:56.028 Error: could not convert string to long long (shell eval):1 | Tue Feb 26 13:45:55.996 Error: could not convert "-18446744073709551616" to NumberLong (shell eval):1
NumberLong(-18446744073709551616)   | NumberLong("-9223372036854775808")       | NumberLong("-9223372036854775808")
NumberLong("9223372036854775808")   | Tue Feb 26 13:45:56.162 Error: could not convert string to long long (shell eval):1 | Tue Feb 26 13:45:56.131 Error: could not convert "9223372036854775808" to NumberLong (shell eval):1
NumberLong(9223372036854775808)     | NumberLong("-9223372036854775808")       | NumberLong("-9223372036854775808")
NumberLong("-9223372036854775808")  | NumberLong("-9223372036854775808")       | NumberLong("-9223372036854775808")
NumberLong(-9223372036854775808)    | NumberLong("-9223372036854775808")       | NumberLong("-9223372036854775808")
NumberInt("4294967296")             | NumberInt(0)                             | NumberInt(0)
NumberInt(4294967296)               | NumberInt(-2147483648)                   | NumberInt(0)
NumberInt("-4294967296")            | NumberInt(0)                             | NumberInt(0)
NumberInt(-4294967296)              | NumberInt(-2147483648)                   | NumberInt(0)
NumberInt("2147483648")             | NumberInt(-2147483648)                   | NumberInt(-2147483648)
NumberInt(2147483648)               | NumberInt(-2147483648)                   | NumberInt(-2147483648)
NumberInt("-2147483648")            | NumberInt(-2147483648)                   | NumberInt(-2147483648)
NumberInt(-2147483648)              | NumberInt(-2147483648)                   | NumberInt(-2147483648)
Number("18446744073709551616")      | 18446744073709552000                     | 18446744073709552000
Number(18446744073709551616)        | 18446744073709552000                     | 18446744073709552000
Number("-18446744073709551616")     | -18446744073709552000                    | -18446744073709552000
Number(-18446744073709551616)       | -18446744073709552000                    | -18446744073709552000
Number("9223372036854775808")       | 9223372036854776000                      | 9223372036854776000
Number(9223372036854775808)         | 9223372036854776000                      | 9223372036854776000
Number("-9223372036854775808")      | -9223372036854776000                     | -9223372036854776000
Number(-9223372036854775808)        | -9223372036854776000                     | -9223372036854776000

The inconsistency comes when handling 2^32. SM effectively "caps" overflows, converting them to the largest possible value (which is negative because this is a signed int), while v8 just converts overflows to zero.

Actual Test                         | SM                                       | V8        
____________________________________|__________________________________________|_________________________________________
NumberInt(4294967296)               | NumberInt(-2147483648)                   | NumberInt(0)
NumberInt(-4294967296)              | NumberInt(-2147483648)                   | NumberInt(0)



 Comments   
Comment by Jonathan Reams [ 13/Aug/15 ]

It looks like this was resolved in a later version of spidermonkey. In the current version we're using all the numbers that are supposed to parse do so correctly.

Generated at Thu Feb 08 03:18:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.