Failed to decode image (Format error decoding Jpeg: Error parsing image. Illegal start bytes:8950)

Hello Forum,

I have a strange problem with my document.

If I import a special image, I am getting the following error:

failed to decode image (Format error decoding Jpeg: Error parsing image. Illegal start bytes:8950)

This is my MfE code:


#image("LifeTime_Profile.jpg", width: 50%, height: auto, fit: "cover")  // Works
#image("LifeTime_Profile_.jpg", width: 50%, height: auto, fit: "cover") // Fails

The two images below (no idea if they will be recoded if I post this) look the same, but they are not.

The error appears with LifeTime_Profile_.jpg only.

This image works in any other image editor/viewer I have and just saving it again (recodes the jpeg) made it work.

WHY!

Running Tinymist 0.15.8 in VSCode under Windows 11 or the current CLI compiler v.0.15.1 makes no difference.

If you rename this file as a.png, does it work with Typst?

https://deepwiki.com/search/failed-to-decode-image-format_f2c36f75-f81b-45a3-baff-4b67d8cf6626?mode=fast points out that 89 50 is the PNG magic signature.

Then, it works indeed!

Why? Is this image in fact a png file with the wrong file name ending and no one ever realized it until now? The image has been used in a Latex document since 2022 at least.

Is the LaTeX image reader so flexible to try reading a jpg file with the png decoder as well, if jpg fails? - unlikely
Or is the Typst jpg image reader so sensitive to fail reading the jpg file if there is some special content? - also unlikely - And if the file pretends to be png, the reader is more flexible trying to read it as jpg, which then works - highly unlikely.

I suspect the first possibility: This file is actually a png file with the wrong extension.
I will have a look using a hex editor…

It seems to be a png with the wrong extension.
It also works fine, if I read it using…

#image("../images/LifeTime_Profile_.jpg", width: 50%, height: auto, fit: "cover", format: "png")

Interesting fact is that neither the Windows Explorer preview, Image viewer, BeyondCompare, nor LaTeX even throws a warning that there is something wrong.

This could be a robustness increase to Typst, if you should ever run out of tickets :wink:

programs (at least under unixoid systems) don’t really care about extensions that much.

if it wants an image format it just reads the file, checks the type and processes it.

typst checks for some extentions and if that fails does the detection.