6 ms·
A similarly lulzy but much more sinister-looking bug happened at Facebook, where an index into an array of users was mistakenly treated as a user id, so the mes
by CGamesPlay 9y ago
A similarly lulzy but much more sinister-looking bug happened at Facebook, where an index into an array of users was mistakenly treated as a user id, so the message intended for user 4 in the array ended up going to the user with ID 4, aka zuck.
- weberc2 9y agoThat sounds like a pretty PHP-specific bug. Downvoters: most programming languages don’t silently convert strings (i.e., usernames) to array indices. Even Python doesn’t do this. While this particular bug probably wouldn’t be possible in most other languages, I’m only commenting because it’s rare and amusing to see bugs that are so language specific. I’m not making a generic “lol PHP” joke.
- kemitche 9y agoBoth array indices and user IDs are numbers. And it's certainly possible in Python to accidentally use a map as a list or vice versa, if the map has integer keys.
- chrfrasco 9y agoPython doesn’t do any implicit coercion (apart from ints and floats etc), right?
- icebraining 9y agoWell, booleans are integers, so you can do: >>> True + 1 2
- ubernostrum 9y agoThat's not "coercion", though. That's Python obeying the LSP, because bool is a subclass of int.
- deleted 9y ago[deleted]
- chrfrasco 9y agofizzbuzz = lambda n: [print((“fizz” * m % 3 == 0) + (“buzz” * m % 5 == 0) or m) for m in range(n)] Not sure if this is great or terrible
- ben509 9y agoIt depends what you mean by coercion. For instance: class Foo: def __getitem__(self, x): return x i = iter(Foo()) print(next(i)) print(next(i)) That works because any object that provides __getitem__ "implements the iterable protocol."[1] I bring up __getitem__ because people familiar with Java are scratching their heads, "not only did you not declare any interfaces, this is just a convention, but there's also an __iter__ method. Huh?" But interfaces are just one way to declare a type. The question is, did it convert it to a new type? Well, what type was it before? If you want to talk about LSP[0], you're a bit stuck here since you can't prove anything about a method in python. (And here, we declared its type, and we said nothing about it being iterable or a sequence.) You have to run it because you don't know that a. Foo has __iter__ or __getitem__, b. that they accept the arguments you're going to pass, c. let alone that they're designed to, d. that the object won't simply delete them halfway through. All that iter() is going to do is look for those methods and make assumptions that if you wrote __getitem__ that you meant it. At which point maybe LSP works, after all, you'll prove that it has that property by running the code and fixing it if it breaks. But... python nevertheless will nevertheless construct this proxy to use your class based on inspection, which seems an awful lot like coercion to me. [0]: Quoth Wikipedia: Let 𝜙(𝑥) be a property provable about objects 𝑥 of type T. Then 𝜙(𝑦) should be true for objects 𝑦 of type S where S is a subtype of T. [1]: https://docs.python.org/3/glossary.html#term-iterable https://docs.python.org/3/glossary.html#term-iterable
- jwilk 9y agoIn Python 2, bytes can be coerced to unicode: >>> b'egg' + u'spam' u'eggspam' Unlike the example with bool+int, this can't be justified by LSP.
- ipsum2 9y agoI've been bitten by this bug before, PHP's associative arrays are pretty strange compared to other languages.
- osrec 9y agoI find it easier to think of them as an "ordered" hash map rather than an array...
- igravious 9y agohttp://php.net/manual/en/language.types.array.php http://php.net/manual/en/language.types.array.php First sentence, “An array in PHP is actually an ordered map.”
- pmarreck 9y agoI just read at least half that page and this idiotic design confirms exactly why I feel PHP should be considered harmful
- osrec 9y agoI don't think it's harmful. You just need to know what you're doing. PHP gets a bad rep round here unfairly. It's actually a very useful language which has proven itself over and over again in the wild. I wonder what you think of JavaScript?
- agency 9y agoJavaScript does. var arr = ["one", "two", "three"]; arr["2"] === "three"; // true
- marcins 9y agoJavaScript object property keys are always strings, so technically it’s `arr[2]` that has the 2 coerced to a string.
- Legogris 9y agoActually, that is incorrect. Arrays are different in JavaScript. I don't have time to look up the exact reference, but to get an idea: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... > Arrays cannot use strings as element indexes (as in an associative array) but must use integers. Setting or accessing via non-integers using bracket notation (or dot notation) will not set or retrieve an element from the array list itself, but will set or access a variable associated with that array's object property collection. The array's object properties and list of array elements are separate, and the array's traversal and mutation operations cannot be applied to these named properties.
- Zalastax 9y agoIt's true that object keys are strings, but the array and object situation of JavaScript is quite confusing. Arrays are indexed by numbers, but still accept string indices, leading to behavior like this: https://stackoverflow.com/q/9526860 https://stackoverflow.com/q/9526860
- CivilEngineer 9y agoDon't make the PHP zealots angry!
- V-eHGsd_ 9y agoanother facebook doozy was their "view my profile as <user>" feature. Apparently for some time after that it was released, when you used it view your profile, you could interact with facebook as <user>; including chatting as them, reading their messages, etc. but then, I've had my share of turrible bugs too, so i'm not here to poke fun.