Space, Time, and Imagination Have No Boundaries, But Your unsigned char Does

Me next to Tardis Police Box in Kensington, London
When you order a new refrigerator, you:

a) measure the space it will occupy and you walk the delivery path to check the width and height of doorways, hallways, and entry ways.

b) OMG! Take the front door off its hinges!!

c) disassemble the refrigerator outside, and reassemble it inside.

Any answer other than "a" would suggest that you are possibly an overworked programmer who doesn't check boundary conditions.

It would also put you in the same company as the programmers who allowed a killer wallpaper to brick certain Android phones. When installed, this wallpaper would send the phone into an infinite loop, causing it to crash, restart, and then crash again. Even safe mode could not break the cycle.

YouTube tech reviewer, Mrwhosetheboss, played detective in this video, pursuing what he first suspected as malware, but then realizing it to be something more mysterious. He even bricked his own phone in the process.



In the end, it came down to one faulty pixel where the calculated luminosity of 256 exceeded the upper boundary for an unsigned char: 255. This screen shot from his video



shows that the programmers took the ceiling when rounding. As a result, the color engine couldn't convert the pixel luminance to the proper color space, and crashed.

At the 9:40 mark in the video, Mrwhosetheboss says something that would scare a manager I know: "It is a pretty easy one to solve. You just need one line of code that says if this value is above 255, then make it 255."

Without seeing the code or knowing how it might affect the color space, I will nevertheless volunteer one other possible solution: instead of rounding using ceiling, try rounding using floor.

On its own, this bug is minor, rare, and hard to duplicate with other wallpapers. But when integrated into the Android boot up cycle, it can cause a serious malfunction. The lessons here are: 
  1. Unit testing is easy. 
  2. Integration testing is hard.
  3. Check your boundary conditions.

Regarding the photo on top, that's me next to the Tardis Police Box in Kensington, London. Fans of Dr. Who know the Tardis is larger on the inside than the outside, thus transcending space. The Tardis also moves through time, and it took me to June 29, 2016. Well, that's what I like to imagine it did.







Comments

Popular posts from this blog

Bookshelf Classic: The C Programming Language

Symmetry

Post Processing: Swift, Kotlin, Team Scaling Fallacy, Levandowski