Why 1/1/1970 Bricks Your iPhone

I wasn't going to do another video
about iPhone bugs, but the 1970 glitch that's been going round
is interesting — because it's probably a type of exploit I
haven't covered before. In short: it is almost certainly an integer underflow
caused by the Unix epoch. And if you understand those terms, you don't
need this video. Everyone else: buckle up, 'cos here we go. January 1, 1970 is a special day for computers.
Back in the 70s, when the UNIX system and all its friends were
being originally designed, the programmers needed a simple way to represent
dates and times, without having to deal with all those awkward
human things like days and hours and minutes. They just needed a ticking clock that it was
easy to do arithmetic on. And the simplest way to do that is just a
number, an integer, representing how many seconds had elapsed
since January 1, 1970. And we're still using that. All over the place, in pretty much every computer everywhere. It's generally the best way to store dates
and times, because it ignores time zones and irritating
human things like that.

Now, I've done videos about it before, so
I won't dwell on it, but all you need to know for this is that
midnight at the start of January 1, 1970 — the date in question — is zero. That's the first clue to what's going on.
Clue number two: it only happens on modern, 64-bit iPhones. Now 64-bit refers to how numbers are stored
on the processor. You've got 64 binary digits to play with, instead of the old 32, which means you can… well, you can deal with bigger numbers, down at the really basic processor level, without having to resort to fancy programming
tricks. Changing the phone, and its operating system, from that old 32-bit system to 64 requires
some work, though, so there'll be subtle differences in the code
between the two. And somewhere, this bug slipped in. Now, showing you 64 bits on screen is a bit
tricky, so let's just use four bits to demonstrate
how this works.

0000 is 0. Then you count up in base 2, in binary, 1, 2, 3, 4, until you get to 15. Biggest number you can store in four bits. You can not count higher than that. But what happens if you try? Well, then you get what's called an integer overflow. After 15 comes… 0. It wraps round and you start again, like an
old, analogue odometer on a car. Now, if you've only got four bits, sure, that's going to be a problem: if you've got
64, well, you're only going to get into trouble when you've counted up past 15 quintillion.
It'll probably be fine. Except. If the largest number you can store,
plus one, comes back as zero… what do you get if you do zero minus one? Well, that's called an integer underflow. You can't store negative numbers in this format. If you can drop the number below 0, you won't
end up with -1, you'll end up with it wrapping around to its
maximum value.

That's why, in the original version of the
video game Civilisation, Gandhi was a dick. He started out with an aggression score of
1. And later in the game, it'd drop further, and no-one wrote code to check it didn't drop
below zero. So instead, it wrapped around, became the
maximum possible, and suddenly Gandhi started declaring war
on everyone. Thankfully, only in a video game. Now. There is a version of this format where
negative numbers are allowed, but if Apple were using that, well, they probably wouldn't have this problem. After all, why would you ever have a negative
time value? It's not like anyone's ever going to do something
like set their iPhone clock back to earlier than
1970(!) And you'll note that you actually can't. If you scroll all the way back, the calendar stops at January 1, 1970, at
zero, because someone at Apple went, no, hang on. That's a bad idea. That could cause a problem. So they set the Unix epoch, as it's called,
the zero time, as the limit.

But if you do set you phone's time to near
zero, then somewhere else in the code, there's a
check — maybe it tries to do a battery time calculation, maybe it just runs the math on when the last
call was, or… well, it's something that no-one's worked
out yet. But whatever that check does, it ends up with a time before January 1, 1970, which just should be a negative integer… except it's not. It's wrapped all the way round, it's giving you a date twenty times longer than the expected lifespan of the universe. And I suspect it may not deal with displaying
that date all that well. But whatever it is, it causes what's formally
known as "undocumented behaviour" and informally known as a crash. Now, I should say that, like always when I
try and break down a bug in an Apple product, this
is speculation: it's unlikely they'll ever confirm exactly
what happened, and it was probably a bit more subtle than
this.

And there is another type of binary integer
— it's called a signed integer — that does handle negative numbers… but that's a story for another time. Even if this isn't exactly what caused it? Well, hopefully it'll stop you making the
same mistake in your code in future. [Translating these subtitles? Add your name here!].

As found on YouTube

The Worst Text You Could Ever Receive…

My goodness, it's terrible Super bad That’s right, it’s a disaster To be honest, the matter is much more serious than I thought A simple text symbol that crashed iMessage Just such a symbol makes iMessage completely unusable but I asked Will to look into it to see what the hell was going on It turns out that the actual situation is much more serious On his Macbook, this symbol crashed Havok directly The Note application on the notebook has crashed Just because there is a note in it that contains this symbol Just need a symbol That’s why I called Will over because he was studying this all morning Let’s test it in different ways to see how bad it is His Android machine is here, there is another one here, and then the iPhone X I will copy this symbol in the SMS chat and send it out, and send it to the Android device using the Android device, so that I can confirm that this is a problem only for iOS and OSX.

let's start My cell phone signal is a bit poor, so… Got it, look Nothing happens on the Android machine But what's going to happen next is a bit risky Just such a simple symbol may directly crash the messaging application on iPhone X Kind of crazy The ghost knows if we find this, will other apps have problems? Give it to Jack, show them Okay, that symbol is there, once the mouse touches that symbol Highlight it… collapsed! Show them what happens when you open the note app The note-taking app can’t even be opened IPhone X on the left, your phone on the right I put my phone card in, it might be a disaster I want to warn you, don't do this! I'm not kidding, it's really bad This symbol may crash your phone Yes, let them see what we are talking about Symbols are copied in The SIM card is read on the iPhone X send Will told me before that this is a foreign language Yes, I think it should be the Indian language Anyway, the language symbols of individual countries What if you are in this country? Do you have this symbol on your keyboard? Everyone is going to collapse The sending speed is a bit slow Why I feel that as long as I send a Test, he won’t crash It takes some time Did the iPhone receive it? Oh My God A little dangerous WOW! The phone restarted directly! If I open the text message, click on this text message Ready? But I don’t know why my iMessage app didn’t crash completely Because my next text message rejected the previous one, so it’s okay If someone is stupid and sends you this symbol, then he is willing to help you He can send you a rescue text message In this case, when you open the SMS, the phone does not need to display this symbol Before I send the rescue SMS, I first try to open the SMS app Now send a rescue text message, and then…

BOOM! I can enter the SMS application now If I take the initiative to open the chat window with Will SMS app will still crash collapsed! But if you copy this symbol in and post it, the iPhone will crash again. SMS arrived Open…crash It crashed immediately, and the text message was completely useless Completely collapsed The extent of this matter is more serious than I thought Apple, I hope you can find some engineers to see what's going on This is a big problem Remember, your Uncle Lewis told you not to do this They don’t realize how much we rely on technology now Just such a small bug immediately makes you panic It’s just a small symbol that makes so many things fall apart Willy Do, thank you for investigating this matter and sacrificing your own computer for presentation I'll go back and use my Pixel 2 XL hhhh, Android device Then I want to send this to Jack Do not! Don't do that! I was kidding, kidding

As found on YouTube