Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8744

NumberInt overflow handling is different in V8 and Spidermonkey

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.1.7
    • Affects Version/s: None
    • Component/s: JavaScript
    • None
    • Fully Compatible
    • ALL
    • Build 7 08/10/15, Build 8 08/31/15
    • None
    • 0
    • None
    • None
    • None
    • None
    • None
    • None

      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)
      

            Assignee:
            jonathan.reams@mongodb.com Jonathan Reams
            Reporter:
            sverch Shaun Verch (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: