The haunted picture: the weirdest bug of my programming life

Rae Knowler
19 Dec 2015, 12:41 a.m.

... so far! This is one that Michelle Sanver and I ran into the other day while we were pair programming, and I'm sorry to report that we still haven't figured out exactly what was going on.

Earlier this week, my colleague Michelle and I were working on what should have been a very simple change to our application. One of its many functions is to take data about the client's upcoming events and output the details as part of our API. We wanted to parse out the URLs of any images associated with events, upload them to our new in-house image service and use those URLs in the output instead of the original ones.

Our first problem was that we couldn't find any events that actually had images to work with. The software used by the client to generate entries for events had a bug itself and nothing could be uploaded. Eventually, after commenting out all kinds of checks for valid events, like the requirement for the start date to be before the end date, we found one test event with an image. Obviously the creator had just grabbed whatever picture they could find on their computer for test data.

The haunted picture

Sidenote: seeing the filename 'Bild-Schwingen.jpg' moved me to try explaining Schwingen to my Swedish coworker. "It's like Swiss sumo wrestling?" (I was wrong: it's apparently more like judo.) We were both quite surprised when the picture loaded.

With that problem solved, we wrote the code to upload the image to the image service and add the new URL to the event. We expectantly ran the importer and looked at the results ... nothing. There was no image URL at all.

After some debugging of the image service, we found the line where exif_imagetype was throwing a read error. Fair enough — we hadn't been catching that. But why was it coming up? Firefox and Gimp had no trouble opening the image, and there was nothing obviously wrong with its EXIF data.

We tried the obvious things: saving the file with a new filename or exporting it to PNG before uploading it. Nothing made a difference. That's when things got really spooky.

Michelle tried uploading a screenshot of the image, and exif_imagetype threw the same bug.

She tried making a screenshot of her desktop and uploading that: no error.

A screenshot of half what we had by now started calling the haunted picture: error.

After several trials, it seemed that a screenshot that included both part of the frame and part of the inner picture would cause exif_imagetype to throw the read error. Just the frame, or just the fairy, worked fine.

I wish I could say we solved the mystery of the haunted picture, but as of today it remains obscure. We had already spent quite some time puzzling it out when we found out that uploading the image to Imgur exorcised it quite nicely, and we decided to temporarily hardcode the output URL to that one so that we could test the rest of our code.

Actual code

If you have a potential explanation, please do leave it in the comments.

Also, if you know the source and artist of the haunted picture, please tell me that and I will make sure to credit it correctly.