… or how to kill 2 days by stupid accident

Again it’s proved to be true how easily can one get confused when looking for a solution to a particular problem. At first glance, the trivial problem when testing gallery (particularly the upload of images) unnecessarily took away 2 days of my life.

Until this moment, everything went smoothly

When working on the gallery development I used a set of several images of different attributes i.e. extremely large/small images, different formats etc. I also tested validation in case the user tries to upload files that are not images.

Until this moment everything went flawlessly.

From here it stopped working

After finishing and final testing in the production version I started using multiple images and tried to simulate the behavior of a regular user. Therefore I got images from various photo banks until I came across the source X = source of my problem.

None of the source X images could be uploaded to the gallery. Other pictures from other sources were totally fine.

1st wrong assumption

I thought the problem was the images themselves from this source. So I focused all my attention on analyzing these images.

It turned out that the images from source X are not entirely standard ones. Several analytical tools also confirmed that their MIME TYPE is just a general application/octet-stream.

I honestly had no idea why this was evaluated as a general octet-stream. Definitely I expected MIME TYPE image/jpeg, image/png or something similar…

The issue with MIME TYPEs, however, helped me to reveal an interesting thing. Symfony framework does use MIME TYPE in the process of image file validation, but image/svg for svg format is missing from the list of supported MIME TYPEs.

The valid MIME TYPE is only image/svg+xml type.

This is because some of svg files are minified and their content starts directly with <svg> tag. Such file has MIME TYPE image/svg — so it does not pass validation and is therefore not evaluated as an image.

For Symfony, the valid svg file must start with <?xml version=”1.0" encoding=”iso-8859–1"?> tag, as required by well-formed XML document syntax.

2nd wrong assumption

One of my colleagues got involved in the process of search for a mistake at one stage who noted that the issue did not show up on a different device. This led me back to the beginning and it occurred to me that the issue might relate to a different development environment.

A different PHP version

Totally desperate and pissed off I decided to change the development environment and the PHP version. The only relevant source for Windows php libraries is https://windows.php.net/download — basically a website the whole world is built on and is used by every developer (apart from Apple positive developers :))

…and of course, just when I needed it, their website was down!

The whole universe ganged up on me like: Go home, the world doesn’t like you. You won’t fix it today anyway.
error.png

After the good while of looking for the right version I finally replicated the environment. And what did I find out?

That there is no issue.

#damn #dogday

Finally the right lead

When I was getting back to the original theory that the issue relates to images themselves, luckily a colleague of mine joined me. He confirmed the issue, but in one of many cases he managed to upload the image.

I began to suspect that the issue could relate to application and environment setup after all.

So what was the problem?

  1. Some functions of image manipulation were not properly treated in the event of an error (Error Exception)
  2. Logging of these exceptions was also incorrect
  3. The problem (surprisingly) wasn’t the image size on the drive, but their extremely high resolution. This means the image processing required much more memory resources.

And the solution?

The solution was to reasonably increase the allocated memory, optimize image processing, and in particular — treat better the exceptions that may arise during the application runtime.

The worst of all, however, was that such a seemingly banal issue became a two-day nightmare. And that’s just because I paid attention to the wrong things that were completely unrelated to the issue. And also due to the coincidence I encountered when debugging.

#gameover #dogday

What do you do when you get stuck in some stupid issue?