How did this image brick Android phones? 
Tags: computerscience, tutorial, webdev, todayilearned
Published: 2020-06-06 03:51:18

Few day's ago this tweet went viral,
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/b4pmqjthzec552a7mf2p.PNG)

People tried it anyway and this was the aftermath : 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rnzorlp2bp626mpccwp4.PNG)

So why is this beautiful landscape picture bricking Android phones? 
 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/36pvc2dvcyrdqd1lz1to.jpg)

The answer lies in one pixel and basic math.

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

As you might remember from CSS, the typical range for <strong> R:G:B<strong> 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](https://dev-to-uploads.s3.amazonaws.com/i/yrqjfng2t960n088v1f7.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/4eika564ft9mfn3iozfc.jpg)

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xjqgobnsam42vgfhftjd.png)

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9wu7c4y235155rf5ygsf.png)

and the overall result of this must be < 255.

But for one pixel the RGB values are: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qg5nk3q4prooe2alv5zl.png)


Doing the math, 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zsqn5vq2pwbh160r7i4d.png)


But android, instead of taking floating value rounds off the numbers: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wueuax5ymsai52zyxji9.png)


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 <strong>overflow</strong> and crashes the phone. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dfauku10luzj6lwrcryg.PNG)

It's fix ? 
```javascript 
   pixel_value = Math.min(255,res);
   //might be more complicated than this but this is my best guess
```

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