richgel999 / jpeg-compressor

C++ JPEG compression/fuzzed low-RAM JPEG decompression codec with Public Domain or Apache 2.0 license
210 stars 57 forks source link

JPEG decoder unexpected marker (RST3) in otherwise valid JPG #22

Open markeel opened 1 year ago

markeel commented 1 year ago

When loading and transforming JPG file created by a user (assume using their phone, but really do not know), the file generated had a marker detected by the jpgd.cpp:1079. I determined which one it was by instrumenting the code until I determined which marker it was.

Other applications (Gimp, Nautilus, Windows Explorer) all display the file and show the image fine.

This was originally discovered as jpeg-compressor is used within the Godot Game Engine which is the tooling used to develop the application.

I suspect that this marker is ignored by most other decoders including stb.

When I used the following command I had success:

$ ./jpge -s bad_file.jpg /tmp/test.jpg 90
jpge/jpgd example app
Source file: "bad_file.jpg", image resolution: 3264x1592, actual comps: 3
Writing JPEG image to file: /tmp/test.jpg
Compressed file size: 945102, bits/pixel: 1.455
Using stbi_load
Compression time: 58.637ms, Decompression time: 24.518ms
Error Max: 20.000000, Mean: 2.633543, Mean^2: 5.956933, RMSE: 2.440683, PSNR: 40.380577
Success.

When I tested decompression I got a failure:

$ ./jpge -d bad_file.jpg /tmp/test2.tga
jpge/jpgd example app
Using jpgd::decompress_jpeg_image_from_file
Failed loading JPEG file "bad_file.jpg"!