bugs

Forum > Bugs > what the?
Reply To Thread (login)
Sir Galahad [53]
2011-04-04 11:34:00
[13 years, 235 days ago]

- 53 hairy chesticles balrog blade <The F5 Tornadoes> 16,777,115 (+16,775,435) 356/815 [0.44] offline Fight Fight

1 <The F5 Tornadoes> balrog blade [53] 1 356 818 0.44 1,299 16,777,055 (+16,775,375)

I think someone has found a bug...


 
Sir Galahad [53]
2011-04-04 11:40:08
[13 years, 235 days ago]

ok agreed that post didn't make much sense :P, WE NEED AN EDIT BUTTON ;)

to clarify: a hairy chesticles - balrog blade has 16,777,115 energy??? Happened from one moment to the other... While he has been offline for at least a day... So some kind of bug me thinks...

Greetings, King Arthur


 
Corruption [60]
2011-04-04 11:41:09
[13 years, 235 days ago]

Ya, i was fighting him, he had normal energy (100 something i think) then it came up [You target is currently fight] went back to the menu and he had 16 million o.O


 
Sir Lancelot [63]
2011-04-04 11:42:54
[13 years, 235 days ago]

his energy is now roun 900, but his monthly is still that high amount


 
Ender [48]
Administrator
2011-04-04 13:08:59
[13 years, 235 days ago]

Energy is stored as an unsigned 24-bit integer, giving it a range of 2^24 = 16,777,216. What happened is that he had a very low amount of energy and the game tried to subtract an energy amount greater than he had, resulting in a negative number. Since energy is stored as unsigned though, this was interpreted as an unsigned integer, causing it to rollover to the upper range.

For why the game tried to take away more energy than he had, first understand that the game does try to make sure it's not taking more energy from someone than they have (because that scenario causes this bug for the reasons described above). And this check normally works and that's why we've gone so long without seeing this until now. Anyway, two attacks came in at exactly 11:31:40. Even this normally wouldn't be a problem, but the interleaving of the parallel execution of the separate processes handling these two attacks happened to both look at the code that says "is it okay for me to take this much energy?", both got the answer "yes", and then both went ahead and did so. Not only was this exact interleaving required for this bug to appear, but the person being attacked had to have an amount of energy less than the sum of the energy being taken away for being attacked. Cue the integer underflow!

This kind of concurrency problem is the kind of stuff they teach you in introductory database courses and it's why you should be using transactions when it's important that certain events are atomic. Fortunately this particular bug is really obvious when it happens, so I'm not going to touch anything for now to see if it happens again. If it continues to be a problem, I'll add in a workaround.


 
Emanuel [110]
2011-04-04 13:19:19
[13 years, 235 days ago]

Very interesting problem :D

Also, http://en.wikipedia.org/wiki/Isolation_(database_systems)#Dirty_reads


 
Ender [48]
Administrator
2011-04-04 13:25:27
[13 years, 235 days ago]

Oh whoops yes, I probably did mean isolation, not atomicity.


 
Ender [48]
Administrator
2011-04-04 15:45:31
[13 years, 235 days ago]

I thought about this some more and there's a fix even more simple than using transactions. Instead of doing "set energy = energy - ?" where the ? is the energy transfer, it could just be "set energy = ?" where ? is the expected end energy.

If this is how it were setup when this situation happened, both bots would get their 16-24 energy (which is still technically incorrect, but really doesn't matter), but the integer underflow would be avoided.

I'm still going to leave it since it's so obvious when it happens and I'm curious to see if it does happen again.


 
Sir Galahad [54]
2011-04-06 12:19:35
[13 years, 233 days ago]

guess it happened again...


 
Ender [48]
Administrator
2011-04-06 12:32:07
[13 years, 233 days ago]

Emanuel set out to reproduce this. I didn't think he'd be able to pull it off, so color me impressed. :p

I'll put in a fix for this when I get home tonight.


 
Warbringer [79]
2011-04-17 12:56:12
[13 years, 222 days ago]

This happened again on Pure Pwnage level 92 :p


 
Sera [110]
2011-04-17 13:27:36
[13 years, 222 days ago]

Up we go beat us all!


 
warrington [105]
2011-04-17 15:26:00
[13 years, 222 days ago]

Guess that fix never happened then haha.


 
Toruk Makto [107]
2011-04-17 15:39:28
[13 years, 222 days ago]

Woop, fixed xD


 
DreamSweet [78]
2011-04-18 02:02:27
[13 years, 221 days ago]

Omg mutex fail lol D:


 
Forum > Bugs > what the?
Reply To Thread (login)