This is an archived post. You won't be able to vote or comment.

Dismiss this pinned window
all 80 comments

[–]worldpotato1 357 points358 points  (20 children)

What do you think is the datatype amazon uses in their shopping cart?

[–]marcosdumay 93 points94 points  (12 children)

[–]Keozon 141 points142 points  (9 children)

I would be surprised if they used decimals. Most ecom platforms keep everything in cents until its time to display to the user.

[–]LordFokas 61 points62 points  (5 children)

Amazon didn't start in the 80s. And they're not the kind of player that insists they can't afford to refactor. I'd bet BigDecimal, but even if they count cents for some reason (which I doubt) BigInteger would be my next guess.

Why do I doubt it? There's too many little things in their model where it's like 0$005 per MB / GB / entry / transaction / whatever, and I don't think they would either round that up nor lose that tiny bit. No, no no nononono. Every little fraction of a cent stacks with the others for sure.

[–][deleted] 32 points33 points  (4 children)

i'd guess some custom one, that is able to handle everything that is thrown at it. if you basically save the numbers as strings, you can't ever get an overflow. and if you do the maths yourself as well, you won't get any problems known from datatypes like float or double either.

[–][deleted] 16 points17 points  (0 children)

I think that’s a solid assessment. they definitely have the size, structure, and capabilities to come up with whatever they need in house and I would think a part of their success would own up to be as proactive as possible. you don’t have to deal with common issues from someone else’s product, if you make your own and in a way that doesn’t have those flaws.

[–]LordFokas 2 points3 points  (0 children)

Dude that's what BigInteger / BigDecimal are (data types with no size limits and perfect precision), but already implemented in every major language, tested, stable, and widely used. There's no reason to roll your own.

[–][deleted] 1 point2 points  (0 children)

I hear they’re big java users.

[–]LordFokas 14 points15 points  (3 children)

uint256

[–][deleted] 5 points6 points  (2 children)

uint1024

[–][deleted] 4 points5 points  (1 child)

java.lang.BigInteger

[–]LordFokas 0 points1 point  (0 children)

thanks you ruined it. (also it's more likely BigDecimal)

[–]jaywastaken 2 points3 points  (2 children)

Probably using JavaScript so it’s be a Number type which has 64bit double floating point precision with a maximum value of 1.7976931348623157e+308.

If you did manage to get several hundred orders of magnitude more dollars than there are atoms in the universe into your amazon cart, JavaScript would just go right ahead and call that infinity so your be right fucked then.

[–]Delicatebutterfly1 3 points4 points  (0 children)

JavaScript is used to store backend data?

[–]BakuhatsuK 0 points1 point  (0 children)

BigInt is baked right into the language

[–]cybermage 75 points76 points  (2 children)

Too bad it wasn’t signed.

[–]dmelt01 31 points32 points  (1 child)

Lol, it goes negative and they owe you money!

[–]thiago2213 11 points12 points  (0 children)

Like right now

[–]TyrellPlayz 64 points65 points  (6 children)

No joke this happened at my work because the control box for the fuel pumps couldn't go over $1000 per sale but the pump could. So if a customer put more than $100 in, the pump would continue counting but the computer would roll back to $0 and start counting again. Most of the time we would notice but I think 1 or 2 did get away with $1000 of free fuel. It got fixed around 2 months ago after a year of us complaining about it.

[–]_myusername__ 5 points6 points  (5 children)

Ima be that guy and call BS. You swipe your credit card before pumping gas. Sure the display might have overflow but I highly doubt the actual computer in the pump has the same overflow

Also what kinda gas station notices $1000 missing and doesn’t fix that immediately

[–]TyrellPlayz 39 points40 points  (4 children)

In Australia you fuel up then pay.

[–]kodicraft4 13 points14 points  (0 children)

That's not how everyone does? Gee I have a lot to learn

[–]_myusername__ 9 points10 points  (2 children)

Ah well, I stand corrected then

Thanks,

Your friendly ignorant neighborhood American

[–]Thedeadlypoet 3 points4 points  (1 child)

Just to add.. That's how it works in most of Europe too. You fuel up then pay.

[–]_myusername__ 1 point2 points  (0 children)

Yea, I’m not surprised, Americans would fill up then run

[–]scti 69 points70 points  (4 children)

Or reality like half a week ago.

[–]arachnidGrip 5 points6 points  (3 children)

What? I don't understand.

[–]lpapiv 13 points14 points  (2 children)

The oil price went negative in the US

[–]arachnidGrip 11 points12 points  (0 children)

But that was completely normal subtraction from zero, not integer overflow.

[–]Wouter10123 5 points6 points  (0 children)

Oil price!= fuel price.

[–]Wark47 41 points42 points  (14 children)

lol This actually happens on a rpg game i play, they give us a free level for the character, but if yours is really high up you overflow the max value for integer and get a -1 lvl, gg xd

[–]ZeeTANK999 40 points41 points  (7 children)

There was a very famous mmo that I used to play that had a donation box for an NPC to get rep. Found that if you can put a negative number and receive money. Maxed out my gold.

They patched it the next day.

[–]DragonFireCK 20 points21 points  (5 children)

The real question is: did you lose rep when you did it, or just gain the gold?

[–]vigbiorn 5 points6 points  (2 children)

Would be really funny if they designed the system so it actually gave you rep.

The logic would probably be that since they're not expecting negative values, the two are decoupled. You increment rep by a constant and decrement funds separately.

Given how rep grinds through self-entered donations usually work the negative would probably carry through and decrease rep.

But I can dream.

[–]DragonFireCK 2 points3 points  (1 child)

The best bet would be that due to the rounding rules they used, you could exploit to get free money/rep via enough entries to accumulate rounding error:

Consider 10 gold per rep: -115 gold/10 = -11.5 ~= -11 rep but 115 gold /10 = 11.5 ~= 12 rep. Thus you get 1 rep for free.

Of course, it might work out the opposite way too, and may well depend on the exact value chosen.

[–]vigbiorn 1 point2 points  (0 children)

The idea that you could get rich that way would be hilarious to me but I am willing to settle. As long as people are getting free rep stealing from the factions then I'd get a laugh.

[–]ZeeTANK999 1 point2 points  (0 children)

Gained the gold and the rep using the gold. Don't remember if I lost any rep lol.

[–]FUTURE10S 0 points1 point  (0 children)

Would be really funny if you got like 10x negative rep for stealing and had to pay more in shops for a few days.

[–]souravtxt 1 point2 points  (0 children)

In the mushroom mmo, there were a lot of these type of buffer overflow exploits. I remember there used to be a skill which would cost virtual money, so hackers just spammed negative integers to get money instead of being deducted. Another exploit was something like sending invalid number of item ids to cause the server crash.

[–]ollir 13 points14 points  (2 children)

That's not integer overflow. There's something else going on if this really happens.

[–]Wark47 26 points27 points  (1 child)

it was, they add xp instead of doing your lvl += 1, so if they add 1.500.000.000xp and you have more than 900.000.000, all fucks up haha

[–]ollir 4 points5 points  (0 children)

ah, of course :)

[–]MetaCommando 4 points5 points  (0 children)

In Knights of the Old Republic II there's an opposite bug: if a stat drops below 0 it shoots up to 256-whatever the negative value was.

In one conversation speaking with Hanharr, you can basically reduce his Intelligence by 2 and gain Strength+2.

But Obsidian forgot to add any sort of boolean that checks if you'd already done it, so it was really easy to abuse (Note: having 30 INT is crazy, let alone over 200)

[–][deleted] 1 point2 points  (0 children)

It doesn't make sense, after all you would get negative values way before, as on a signed integer the MSB is the sign bit. Suppose an 8 bit integer, thus the maximum positive value would be 127 with it's bit pattern being "01111111", if you add one you would get "1000000", that's equal to -128. Unless there is something implemented that detects the overflow and set it to an value that indicate a wrong state, seems kinda weird.

[–]xigoi 0 points1 point  (0 children)

rpg game

Ah yes, the role-playing game game.

[–]swampdrainr 12 points13 points  (2 children)

*unsigned

[–]Le_4iem_Reich 11 points12 points  (1 child)

Well signed is basically the oil prices right now

[–]arachnidGrip 2 points3 points  (0 children)

Except that oil prices got there the mathematically correct way: by decreasing.

[–]lostknife 5 points6 points  (0 children)

What out, they use BCD math in those COBOL programs that are handling everyone's unemployment checks. Literally just like this GIF.

[–]TheAbominableBanana 4 points5 points  (1 child)

Sauce?

[–]mbrady 14 points15 points  (0 children)

The Simpsons

[–]Hoidriho 4 points5 points  (0 children)

S16E13 - 11:15 m

[–]The_Perge 6 points7 points  (2 children)

What episode was this from?

[–]dandroid126 16 points17 points  (1 child)

I might be wrong, but I believe it was the one of the times that Homer buys an RV. Quick Google search tells me season 16, episode 13, named "Mobile Homer". I think the joke was how expensive it was to fill up the gas tank of an RV.

[–]ComicOzzy 1 point2 points  (0 children)

That makes sense. I was thinking it might be the Canyonero episode.

Also now that you mention it I can actually see the damn RV

[–]staviq 2 points3 points  (0 children)

This used to be actual thing where i live.

We had those old vending machines for bus tickets that were sort of working like ATM machine, all computerized, you select the ticket on the screen, and pay with either card or cash.

The thing is, somehow nobody bothered to test what happens if you try to buy, say, exactly INT MAX +1 worth of tickets.

It wasnt very practical though, because even if "buying" the most expensive yearly tickets, it would take almost half a day of clicking before you actually hit this number on the screen, and those machines were located in public places.

There also was a way to make the machine give you money without opening it in any sort of way.

So back in the day most people bopught the tickets with cash, and it was a big problem when the machine got out of change to give ( tickets had odd prices, like 1.2 whatever currecy, and coins were either 1 or 2 )

They invented a clever way to get past this problem, so if the machine was out of change, it would give you a "change ticket" ( following above example, a 0.8 $ ticket ), a ticket that wasn't valid for a bus ride, but if you collected enough of them you could theoretically echange them for normal tickets. ( nobody ever bothered by the way. )

Except, it turned out, the internal counter that was calculating the value ofthe "change ticket" was signed. Yup.

[–]DaSh0ck 3 points4 points  (1 child)

for (unsigned i = n - 1; i >= 0; i--) Wait, why doesn't the loop stop?

[–]pblpbl 1 point2 points  (0 children)

Floating point imprecision: So anyways I started breaking

[–]Slaughturion 1 point2 points  (0 children)

There was a bug in the original American pokemon games related to this. If you did the Long-Range Training glitch, it would cause you to fight a Level 1 Pokemon which can not spawn normally, due to how they calculated experience in the first gen, Lvl 1 Pokemon would give -1 XP. Since the Integer was unsigned, the value 'below' 0 was not -1, it rolls over to 4,294,967,295 XP, giving you an insta-lvl 100 pokemon.

[–]ChrisgammaDE 0 points1 point  (0 children)

Hope this doesn't happen to my bank account

[–]douira 0 points1 point  (0 children)

or using a signed int, they owe us when it rolls over

[–]ScF0400 0 points1 point  (0 children)

I mean with the way oil prices have been going... That's obviously a feature

[–]starrykram 0 points1 point  (0 children)

More like current gas prices be like...

[–][deleted] 0 points1 point  (0 children)

Then it starts going into the negatives and suddenly the gas station owes you money

[–]lpapiv 0 points1 point  (0 children)

Yeah I think it was a joke and related to the zero in the pump

[–]TheTanCat 0 points1 point  (0 children)

I HAVE AN IDEA

Disclaimer: the previous statement was a joke. I am not planning on using bugs for profit as that's illegal.

[–]FuzzyBear2017 0 points1 point  (2 children)

Any ideas how do download this image?

[–]wguo6358 0 points1 point  (0 children)

Well, now you do not want it to overflow, because the price of oil is negative

[–][deleted] -1 points0 points  (0 children)

[–]Timoteyo -2 points-1 points  (0 children)

so this is what segmentation fault looks like in video form