mojira.dev
MC-79954

Integer overflow of scoreboard

The Bug:

Integer overflow of scoreboard.

Steps to Reproduce:

  • Run the following commands:

/scoreboard objectives add test dummy
/scoreboard objectives setdisplay sidebar test
/scoreboard players set @s test 2147483647
/scoreboard players add @s test 1
  • โ†’ย โŒ ย Notice how your score is "-2147483648".

Linked issues

Attachments

Comments 26

the number becomes too big for an integer, so it goes to the lowest value possible.

I am going to move the link to a different channel soon, so the link will change.

Updated the YouTube link ๐Ÿ˜›

Confirmed for

  • 1.8.4

Relates to: MC-80096 (mainly to the part with potions and filled_maps)

You can easily reproduce this:

  1. /scoreboard objectives add Test dummy

  2. /scoreboard objectives setdisplay sidebar Test

  3. /scoreboard players set @p 2147483647

  4. /scoreboard players add @p 1

Marcono1234, yes you can but I think it is easier to make a video ๐Ÿ˜›

16 more comments

What do you guys expect Mojang to do exactly? Integer overflow is gonna happen no matter what if you input a high enough number.

It should just stop at 2147483647. Alternatively, a bigger number type (like "long") would make it practically impossible to reach the limit, but at the cost of slightly higher network traffic.

This kind of inconsistent arithmetic would honestly be worse IMO. Making it a long (or possibly even a bigint since IIRC the scores are stored as strings anyway) would be a much better solution.

The only fix I can see happening for this is changing it to longs (which is just moving the issue); command contraptions can easily check if it would overflow, and if undesired, prevent it. Throwing an error message only feels like it could prevent some things from working.
Also, correcting the above comment, scores are saved to files as ints, not strings

Yep. I double checked and indeed they are stored as ints. I wonder why I thought they were stored as strings; perhaps at one point they were or perhaps I misremembered. In any case I don't think there is any possible fix besides changing scoreboards to long (which like you said just moves the issue) or bigint (which would work but comes with its own set of problems).

Trey Ruffy

Avoma

(Unassigned)

Confirmed

(Unassigned)

Minecraft 1.8.4, Minecraft 1.10.2, Minecraft 16w42a, Minecraft 1.12.1, Minecraft 1.12.2, ..., 1.17.1, 21w38a, 21w39a, 21w40a, 21w42a

Retrieved