Page 1 of 1

identify doesn't detect corrupt JPEG files (Firefox does)

Posted: 2011-12-22T03:26:10-07:00
by sourcejedi
I wrote a little script to scan my photo collection / backups for errors using "identify" ("reports if an image is incomplete or corrupt"). Unfortunately it doesn't work. I tested it by null-bombing an image file using dd. (I repeated this a couple of times with different settings).

Code: Select all

dd conv=notrunc seek=30 count=1 if=/dev/zero of=test.jpg
Identify doesn't notice the corruption:

Code: Select all

$ identify test.jpg
test.jpg JPEG 3409x2392 3409x2392+0+0 8-bit DirectClass 1.216MB 0.000u 0:00.000
$ echo $?
0
Here's my version information:

Code: Select all

# libjpeg package has the version number "6b-15ubuntu1"

$ identify --version # (compiled from source)
Version: ImageMagick 6.7.1-10 2011-08-25 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

$ ldd `which identify`
        linux-vdso.so.1 =>  (0x00007fff839ff000)
        libMagickCore.so.4 => /usr/local/lib/libMagickCore.so.4 (0x00007ffd64e9a000)
        libMagickWand.so.4 => /usr/local/lib/libMagickWand.so.4 (0x00007ffd64baa000)
        libtiff.so.4 => /usr/lib/libtiff.so.4 (0x00007ffd64947000)
        libc.so.6 => /lib/libc.so.6 (0x00007ffd645c4000)
        libjpeg.so.62 => /usr/lib/libjpeg.so.62 (0x00007ffd643a0000)
        libpng12.so.0 => /lib/libpng12.so.0 (0x00007ffd64178000)
        libz.so.1 => /lib/libz.so.1 (0x00007ffd63f61000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x00007ffd63d44000)
        libltdl.so.7 => /usr/lib/libltdl.so.7 (0x00007ffd63b39000)
        libdl.so.2 => /lib/libdl.so.2 (0x00007ffd63935000)
        libgomp.so.1 => /usr/lib/libgomp.so.1 (0x00007ffd63727000)
        libm.so.6 => /lib/libm.so.6 (0x00007ffd634a3000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ffd6542d000)
        librt.so.1 => /lib/librt.so.1 (0x00007ffd6329b000



But if I use Firefox instead, the corruption is detected correctly:

Code: Select all

$ firefox "/home/jenkins-photos/1925 - 2009 Ken/1993 Young Alice 'helping' Grandad.jpg"
Corrupt JPEG data: premature end of data segment
Corrupt JPEG data: premature end of data segment

identify doesn't detect corrupt JPEG files

Posted: 2011-12-22T03:52:08-07:00
by sourcejedi
"convert" works, but it's not easily scriptable, because it still returns a "success" exit code.

Code: Select all

$ convert test.jpg /dev/null
convert: Corrupt JPEG data: premature end of data segment `test.jpg' @ warning/jpeg.c/JPEGWarningHandler/325.
$ echo $?
0
I can't find a "-strict-errors" option. (What I'd really prefer is aborting on errors by default, which would be a good idea for user scripts / batch use in general).

Re: identify doesn't detect corrupt JPEG files (Firefox does

Posted: 2011-12-22T06:21:41-07:00
by magick
You want:
  • -regard-warnings pay attention to warning messages

Re: identify doesn't detect corrupt JPEG files (Firefox does

Posted: 2011-12-22T06:47:15-07:00
by glennrp
"identify" doesn't read the entire image. Try "identify -verbose" which does read it all.

Re: identify doesn't detect corrupt JPEG files (Firefox does

Posted: 2011-12-22T07:16:09-07:00
by sourcejedi
Both of those work as you describe. Thanks!

Re: identify doesn't detect corrupt JPEG files (Firefox does

Posted: 2013-05-23T13:22:59-07:00
by arv
I'm currently using:
- ImageMagick-6.2.4-5-Q8-windows-dll.exe 32-bit,
- ActivePerl-5.8.7.813 32-bit,
- windows 2008 R2 Std 64-bit.

In this configuration, the detection of corrupted JPEG files works as expected, ie returns a message:
Exception 325: Corrupt JPEG data: premature end of data segment 'file.jpg'
both when calling:
- "identify.exe corrupted.jpg"
- Read method of PerlMagick: $result = $i->Read( 'corrupted.jpg' );

I tested the following configurations:
- ImageMagick-6.8.5-7-Q8-x86-dll.exe with ActivePerl-5.16.3.1603 (Windows 2008 R2 64-bit),
- ImageMagick-6.8.0-Q8 with ActivePerl-5.14.2 32-bit (Windows 2003 32-bit),
- ImageMagick-6.7.7-Q16 64-bit with ActivePerl 5.14.2 64-bit (Windows 7 64-bit).

In all these configurations, both Read method of PerlMagick and "identify.exe -regard-warnings corrupted.jpg"
does not detect corrupted JPEG files - no warning message.


BTW, how to use Identify method of PerlMagick, regardless of the version of IM my perl script:

Code: Select all

my $FileJPG = 'corrupted.jpg';
my $Img = Image::Magick->new;
my $Wynik = $Img->Read( $FileJPG );
open( IMAGE, $FileJPG );
my $Result = $Img->Identify( file => \*IMAGE );
close( IMAGE );
crashes with following errors in windows application event log:
no such element in list `c'
no such element in list `Image'
unable to open module file `C:\Program Files (x86)\ImageMagick-6.2.4-Q8\modules\coders\IM_MOD_RL_Image_.dll': No such file or directory
no such element in list `JPG'
Faulting application name: perl.exe, version: 5.8.7.813, time stamp: 0x42a4b40a
Faulting module name: ntdll.dll, version: 6.1.7600.16915, time stamp: 0x4ec49d10


Any advice is welcome.