DEV Community

Cover image for How did this image brick Android phones?
Akhil
Akhil

Posted on

How did this image brick Android phones?

Few day's ago this tweet went viral,
Alt Text

People tried it anyway and this was the aftermath :
Alt Text

So why is this beautiful landscape picture bricking Android phones?

Alt Text

The answer lies in one pixel and basic math.

A pixel comprises of a color and a color comprises of three basic colors, Red, Green, Blue or RGB.

As you might remember from CSS, the typical range for R:G:B lies between 0 - 255, and android handles it well. But there's a huge range of color space which android doesn't understand and converts it RGB.

What's color space? It's basically this :
Alt Text

as you might see, the android sRGB space is narrow compared to other color spaces, but how is this relevant?

The above image was captured in Prophoto RGB color space, so when you open the image in the gallery, android tries to convert the image into sRGB color space, and here lies the problem.

Even dev.to converts it to relevant color space :
Alt Text

There's one pixel in this image that causes this issue.

Alt Text

So when Android comes across a photo whose color space it doesnt support it modifies the image by the following formula :

Alt Text

and the overall result of this must be < 255.

But for one pixel the RGB values are:
Alt Text

Doing the math,
Alt Text

But android, instead of taking floating value rounds off the numbers:
Alt Text

Since 256 above the max limit, android throws an error. When we open the image in the gallery, it encounters the error and just might shut off the gallery.

But when we set the image as a wallpaper, it's like setting up an endless loop of errors. At some point the overflow and crashes the phone.
Alt Text

It's fix ?

   pixel_value = Math.min(255,res);
   //might be more complicated than this but this is my best guess
Enter fullscreen mode Exit fullscreen mode

Crazy isn't it? How one pixel could crash our phones.

I hope you liked my article. Until next time :)

Source : https://twitter.com/UniverseIce/status/1266943909499826176
https://www.youtube.com/watch?v=iXKvwPjCGnY
https://del.dog/suthokuxid.log
https://twitter.com/HrX2003/status/1267049418659901440
https://hdqwalls.com/wallpaper/5120x2880/sunset-at-st-mary-lake-glacier-national-park-5k

Discussion (34)

Collapse
steveblue profile image
Steve Belovarich

Excellent write up! That’s interesting. Probably just a bug and considered an edge case, which is why it wasn’t caught. Very few people work with such wide color spaces, probably professional photographers. When photographers print, the color space has to be converted to whatever is most compatible for the printer / material, so there happens to be a long history of algorithms that convert color spaces.

I see this as a symptom of a much larger problem in user interface engineering. What do you expect from engineers that often ignore design / UX, where the engineers often have zero grounding in graphics processing despite coding user interfaces?

Collapse
nicobistolfi profile image
Nico Bistolfi

If developers use more defensive programming this would have never happened.

Collapse
akhilpokle profile image
Akhil Author

Color spaces are usually used so that what photographers/printers see on screen is exactly printed on paper.

I guess this was more of carless rounding of numbers.

Collapse
jmojico profile image
Julian Mojico

I love to read this kind of stuff in dev.to....it's much more different that the rest of the articles like "Top 5 frameworks in javascript".

I was wondering... Is there any quick fix for this bug?
Once you setup a wallpaper, the only way to change that is successfully boot Android OS, and only then, you would be able to change the buggy wallpaper. :O

Collapse
akhilpokle profile image
Akhil Author

Thanks for reading the article :), I like to write about how tech works and real-life applications of algorithms etc.

And yep you're correct. Unfortunately, the fix for this was to reset the phone. Google is planning on releasing its fix soon in future updates.

Collapse
nicobistolfi profile image
Nico Bistolfi

I agree with @jmojico , great and entertaining article @akhilpokle

Thread Thread
akhilpokle profile image
Akhil Author

Thanks for reading my article :)

Collapse
joeyprogramy profile image
Joey Programy

Amazing, how just one pixel can create such a huge madness. I saw this one thing on twitter, I was a little skeptical, but then I remembered that character that broke iPhone's some time ago.

Cool post and great explication!

Collapse
akhilpokle profile image
Akhil Author

Yea, and to make it even worse errors like these occur very rarely and it's tough to replicate them. Thanks for reading :)

Collapse
thekashey profile image
Anton Korzunov

Why when white color (255,255,255) is not crashing anything?

Collapse
akhilpokle profile image
Akhil Author

Interesting catch. Need to dig deeper regarding this. Thanks for pointing out :)

Collapse
ctinguria profile image
Chetan Tinguria

Hey Akhil - nice article, easy to understand.
I feel that the fix will be in two parts:

  1. the one you are proposing, after the summation
  2. the rounding off should be proper, like 54.213 should be 54 and not 55, while 17.5446 can be 18.
Collapse
msfjarvis profile image
Harsh Shandilya

Interesting read. This was patched in Android 11 properly and since backported by a LineageOS developer here, clamping down the value simply hides the problem.

Collapse
munafsheikh profile image
Munaf Sheikh • Edited on

Hi Akhil,

Very interesting article and great write-up.. Obviously I tried it for myself and can verify it did the same on my Samsung Note 9.

I was able to resolve it although it was challenging. It was a race against the device's startup services.

As your device boots up,

  1. Delete the image from your gallery,
  2. change the wallpaper on home screen.

I suppose I was very lucky I applied that image as wallpaper on the homescreen only - not both home screen and lock screen. I will not be doing this again.

This experience also raised a question for me on how to log in to Android via a terminal (on the device or off) and avoid starting the GUI manager up..

Cheers

Collapse
akhilpokle profile image
Akhil Author

Awesome man ! Smart that you applied only to the home screen.

Collapse
devworkssimone profile image
DevWorksSimone

Here the dumbest question 😅 how you show original color in dev.to if dev.to converts it? Very interesting article.

Collapse
akhilpokle profile image
Akhil Author

There's an interesting happening in the background.

If you directly apply this wallpaper then it will crash your phone, but if you take a screenshot of the image and then set it as wallpaper, it works fine. that's because, in gallery, android converts the photo to sRGB.

Tech becomes crazy as we deep dive into it.

Now what I did was, upload this image on a website that supported the ProPhoto color space, then I uploaded the image converted by dev.to, combined and downloaded as sRGB.

Due to this original colors were preserved.

Collapse
cartinez profile image
F. • Edited on

You might also say that.. a pixel is killing Pixels.

I'll see myself out.

Collapse
paularah profile image
Paul Arah

wow. thanks for sharing!

Collapse
akhilpokle profile image
Akhil Author

Thanks for reading :)

Collapse
pilskalns profile image
Andžs

If this article gets 256 likes, will it crash dev.to?

Collapse
akhilpokle profile image
Akhil Author

Share it to reach the 256 goal :P

Collapse
arnabdeypolimi profile image
Arnab Dey

careless use of round function

Collapse
akhilpokle profile image
Akhil Author

Yea. This issue used to appear rarely on Reddit and it's apparently it's hard to miss the bug, but this time they caught it.

Collapse
chthierry profile image
Christophe

Amazing ! I think this article will be my new reference when explaining the difference between rounding each term and rounding the total ;-)

Collapse
akhilpokle profile image
Akhil Author

Thanks for reading the article :)

Collapse
l04db4l4nc3r profile image
Angad Sharma

Amazing read!

Collapse
akhilpokle profile image
Akhil Author

Thanks alot !!

Collapse
dansimiyu profile image
dan-simiyu • Edited on

This is really a good piece. Thanks.

Collapse
akhilpokle profile image
Akhil Author

Thanks alot for reading :)

Collapse
meatboy profile image
Meat Boy

Awesome analyze and weird Bug :D great article

Collapse
akhilpokle profile image
Akhil Author

Thanks man ! :)

Collapse
tilakmaddy_68 profile image
Tilak Maddy

this blew my mind

Collapse
proxcentaur profile image
Proxima Centauri

Awe-inspiring!