How did this image brick Android phones?

How did this image brick Android phones?
243 33

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

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

Build with &
Edit dev-to-clone-nuxt Edit dev-to-clone-nuxt