Articles Blog

Why 1/1/1970 Bricks Your iPhone

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!]

100 thoughts on “Why 1/1/1970 Bricks Your iPhone”

  1. I had a game on a steam, and i bought a dlc to it.

    When i want to see at the list of all my dlc to this game, i see it, but with date of bought – 1970-01-01 lel

  2. while yes it does, it can also just be the download date of movies/ music etc. I have a movie that says i downloaded it in 1921 xD

  3. Why do they even let you set your phones date in the past it's useless unless you time travel if it's even possible

  4. Isn't an 'underflow, to do with imprecise floating point values? Regardless of whether a number is bigger than the max value or smaller than the min value, it will be known as an 'overflow'.

  5. Expected lifespan of the universe that short? I think you meant of the Earth, or Solar System, or Sun

  6. This is cool beans!!!
    Even my flip phone won't go back before 1-1-1970, i just checked. I never knew why some phones, computers, etc did that. Thanks!

  7. or the simple answer is that anything before jan 1970 is a lie… so your grandparents and everything in the world is a lie the universe is a lie time is a lie everything IS A LIE

  8. Hold on so why did I have this on my android phone. I was on a train. And my phone froze so naturally I held the power button until the screen went off then I took the battery out then put it in after a couple of second then powered it on then I got this date. The phone was a Doro smart phone. Exact model is unknown but nonetheless it happened but why

  9. Why is any one setting their dates to1970 anyway? Y'all got some deloreans in the back? At&t 4g networks work in 70s? Jeez. Might as well set phones to 2770 while y'all at it

  10. People REALLY don't understand unsigned arithmetic.
    One of the tricks with using an unsigned counter like this is the fact that if you subtract a starting count from the current count, you get the difference even if the counter had overflowed between the start and final values.
    For instance, in binary, if your beginning count is, say, 14 (1110b) and it ticks three times, giving you 1 (0001b) after it overflows, if you take the final value and subtract the beginning value (1 – 14) you get, 3! This is very useful in some realtime embedded systems.
    I learned these back in the dark ages of computers and I tried to use it a few years ago. My boss, and every young programmer on the project just didn't believe it would work. I ended up writing about 50 lines of comments explaining how it works just to satisfy them.
    Sometimes being a software engineer is frustrating.

  11. i have a question, numbers are infinite and computers only do what they were designed to do by the information given to them by humans, so wont it fail when it reaches the highest number a human can count to?

  12. why are there a 80000 fortnite players complaining about this video, you’re all 12 and nobody takes you seriously

  13. I couldn’t help but laugh at the fact that a phone can be set to 20x the life span of the entire universe and breaking as a result

  14. My old ipod touch was disabled and couldnt be unlocked gor 92827227622626525255252 seconds. Could this be the result of that?

  15. I want to give a giant belated thanks to whomever ran the numbers on the 64-bit integer underflow. I now know that my phone will brick itself half-past 3:00 pm on April 12.

  16. Very late but, for those wondering:

    Why 1970? Because the people who designed UNIX chose it. There's no special reason.

    Why "bricked"? Because if you set the clock to 1970-1-1 and restart the phone, it won't start up anymore, making it about as useful as a brick. (I'm sure it's been fixed by now though.)

    Why no negative numbers? Because in a computer you only have '0' and '1'. You don't have '-'. You can tell your program to interpret one of those digits as meaning positive or negative instead of being part of the actual number, but they didn't bother to do that here.

    Why does this prevent the phone from starting up? No idea. Some code doesn't handle this situation correctly and does something wrong.

  17. An old video, I know, but I am left wondering.. Is this integer, the one this computer is keeping track of, the one every phone and clock in the world keep track of? I mean the info has to come from somewhere! How do people keep track of the exact time? My mum and dad both had alarm clocks that checked the time with someplace so that they wouldn't be wrong. Where does all this happen and how?

  18. Easy fix: Change the interface to not allow anyone to set a system date before some time much more recent, but leave the background code to the 1-1-1970 start date for compatibility (no need to change the OS).

  19. You rattled on too fast. Slow down and tell us how to lockup/brick our phones. There are thousands of morons that will try exactly that. Cool! Apple will love you! More phone sales, etc…

  20. i had this glitch in my really old samsung phone, under the whatsapp story date. it was 01/01/1970,1.59

  21. What's the point of being able to set your date in your phone to the past? Why not just have it where you can only go back to the day it was completely manufacturered?

  22. So what I’m hearing you say is the phone crashes bc it basically travels into the future past the end be of the universe.

  23. My facebook messenger is showing me some of my call history, somewhere around 1970. It was 4:00 am that day and I was shocked cuz it's saying that call was from 1970. Creepy

Leave a Reply

Your email address will not be published. Required fields are marked *