Wallpaper crash explained: Here’s how a simple image can soft-brick phones

Davide graciously explained for Android Authority readers how an image can cause such problems, cautioning it’s his “personal take.” Below is a lightly edited explanation from him:

The main issue right here is that SystemUI only handles sRGB images for the wallpaper and doesn’t have any check against non-sRGB wallpapers. This can lead to a particular crash in the ImageProcessHelper class, as a variable used to access an array goes over the array bounds.

This variable is called y, and it’s the sum of the current scanned pixel rgb values. This pixel is obtained from scanning every row and column of the greyscaled picture surface. Every time we get a pixel, we assign to y the sum of its rgb values (usually max is 255) and use said variable to access an element of the histogram array (which size is 256 max) and do stuff with said element.

Now, for normal greyscaled images the sum of rgb values is always 255, but this is no normal image. The variable y goes over 255, and it generates an out of bounds exception (any exception in SysUI is treated as fatal, leading to an infinite loop of crashes because the image gets processed every time SysUI starts). Now, one solution could be to add a check after y is assigned a value that basically sets y to 255 if it ever goes over the max bound. This actually works, but we get worse quality for some reason.

The LineageOS guys were able to find out that this particular issue happens because of poor rounding, mostly because the rgb values were always rounded to ceil instead of normal rounding. They were able to fix it by manually rounding the values and apparently this method also retains quality, but I really don’t see how, mostly because SysUI seems to always convert the image to sRGB, leading to a color loss when the color space is larger.

I also tried crafting my own broken image with photoshop or gimp, but SysUI always converted the image to the safe color space, leading to no crash (but a loss of colors ofc). I even tried extracting the broken image color profile and using it in a new image, but still couldn’t get SysUI to crash.

ncG1vNJzZmivp6x7orrDq6ainJGqwam70aKrsmaTpLpwrc2dqaihlGLEorjLqZipnaJisLOt0qFkamliaYJ4g44%3D