Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
I'm writing a script to recursively test JPGs for corruption using imagemagick to open and resize the image.
And on testing the error codes returned on a known bad jpg I always get a "0" success.
convert -resize 100 BNE4_0288.jpg /tmp/out.jpg
convert-im6.q16: Corrupt JPEG data: found marker 0xea instead of RST5 `BNE4_0288.jpg' @ warning/jpeg.c/JPEGWarningHandler/352.
convert-im6.q16: Corrupt JPEG data: found marker 0xea instead of RST6 `BNE4_0288.jpg' @ warning/jpeg.c/JPEGWarningHandler/352.
convert-im6.q16: Corrupt JPEG data: found marker 0xea instead of RST7 `BNE4_0288.jpg' @ warning/jpeg.c/JPEGWarningHandler/352.
convert-im6.q16: Corrupt JPEG data: found marker 0xea instead of RST0 `BNE4_0288.jpg' @ warning/jpeg.c/JPEGWarningHandler/352.
convert-im6.q16: Corrupt JPEG data: found marker 0xea instead of RST1 `BNE4_0288.jpg' @ warning/jpeg.c/JPEGWarningHandler/352.
ETC!!
echo $?
gives me a 0.
if I check out.jpg it's truncated and mostly grey. Sure it was made, but I wouldn't call that a '0'.
The corruption seems to be random bytes/blocks corrupted by a bad USB flash drive.
I've also just tested it with a truncated image made using dd count=xxx and it also fails:
convert-im6.q16: Premature end of JPEG file `qqq.jpg' @ warning/jpeg.c/JPEGWarningHandler/352.
convert-im6.q16: Corrupt JPEG data: premature end of data segment `qqq.jpg' @ warning/jpeg.c/JPEGWarningHandler/352.
I would have thought this would be a more sensible default and -disregard-warnings should be the option.
Feel free to move this out of the bug section though.
#!/bin/bash
newline='
'
OIFS=$IFS
IFS=$newline
files=($(find . -iname "*.$1"))
IFS=$OIFS
for i in "${files[@]}"
do
echo -n "Testing: $i.."
convert -regard-warnings -resize 100 "$i" /dev/null
error=$?
if [ $error -ne 0 ]
then
echo "this didn't work!!"
echo "$i"
echo "$i" >> ~/brokenJPGs.txt
file "$i" >> ~/brokenFILE.txt
else
echo "OK"
fi
done
wc ~/brokenJPGs.txt
exit 0
Make sure you pass the extension to test as the first argument. It produces a file called brokenJPGs.txt as a file list for further processing. And brokenFILE.txt which has the 'file' output to find misnamed things etc.
IM raises an error when it can't read an image, or can't create an output image, and so on. If there is a problem with data or metadata, but IM can still process the image, it raises a warning.
Personally, I would like an extra level, so we might have:
3: can't process the image
2: can process the image, but it is probably wrong (eg "corrupt JPEG data")
1: can process the image, but it's probably okay (eg "ASCII value for tag "Make" contains null byte in value")
0: no problem at all