Execution of the processing of the corrupted files
for filename in vips*.*; do
echo "-------------------------------"
echo "$filename"
vips tiffsave "$filename" "output-$filename.tif" --tile --pyramid --tile-width 256 --tile-height 256 --compression "jpeg"
echo "Exit code: $?"
done
Output:
-------------------------------
vips-padded.png
(vips:97162): VIPS-WARNING **: 16:21:31.715: pngload: end of stream
...
(vips:97162): VIPS-WARNING **: 16:21:31.720: pngload: end of stream
Exit code: 0
-------------------------------
vips-truncated.png
(vips:97177): VIPS-WARNING **: 16:21:31.768: pngload: end of stream
...
(vips:97177): VIPS-WARNING **: 16:21:31.773: pngload: end of stream
Exit code: 0
-------------------------------
vips.txt
VipsForeignLoad: "vips.txt" is not a known file format
Exit code: 1
-------------------------------
vips.xml
magickload: Magick: unable to read image data `vips.xml' @ error/svg.c/RenderRSVGImage/457 (null)
Exit code: 1
Conclusion
The vips CLI does not care about the filename extension, it tries to guess the type of the file from its content.
When handling fully corrupted images (e.g. TXT or XML file), the vips CLI returns an error code of 1 and prints an error message in stderr.
When handling partially corrupted images (e.g. truncated or padded PNG file), the vips CLI generates valid outputs (but with an incomplete image), returns without any error code (i.e. 0), but does print some errors in stderr indicating that some of the processing went wrong.
Adapting the usage of pyvips to properly handle corrupted images
The pyvips library throws the pyvips.Error exception in case of problems when processing an input image.
The linked pull request adds a try/except around the image generation and logs an exception in order to not let the celery task fail in case of image processing problem.
Testing of corrupted images
Creation of the corrupted image files
echo -e 'Some text file\nwith some content.' > vips.txt
echo -e '<?xml version="1.0" encoding="UTF-8"?>\n<Some><XML>File</XML><Message>With some comment</Message></Some>' > vips.xml
Execution of the processing of the corrupted files
Output:
Conclusion
Adapting the usage of pyvips to properly handle corrupted images
pyvips
library throws thepyvips.Error
exception in case of problems when processing an input image.try/except
around the image generation and logs an exception in order to not let the celery task fail in case of image processing problem.