#218 GM returns 0 when failing on corrupted image

closed-wont-fix
5
2012-12-31
2012-11-27
No

Hi all,
I\'ve just upgraded GM to 1.3.16 and one of my tests is now failing. It seems that GM returns 0 though it fails processing a corrupted image (truncated jpeg file).

ci@factory-server-01:~$ gm convert corrupted.jpg -rotate \'90.0\' -quality \'90.0\' out.jpg
gm convert: Unsupported marker type 0xb5 (corrupted.jpg).
ci@factory-server-01:~$ echo $?
0

With the previous version (1.3.12), it returns an error code (1).

ci@factory-server-01:~/gm-1.3.12-q8/bin$ ./gm convert ~/corrupted.jpg -rotate \'90.0\' -quality \'90.0\' ~/out.jpg
./gm convert: Unsupported marker type 0xb5 (/home/ci/corrupted.jpg).
ci@factory-server-01:~/gm-1.3.12-q8/bin$ echo $?
1

The problem is also reproducible with 1.3.17
The input file is attached.
The output file is produced and though the file size is slightly less than the input file (495KB Vs 1.2MB), it looks like the input file (+ the rotation).

Discussion

  •  
    Attachments
  • Testing with your truncated file reveals that libjpeg is reporting a warning rather than an error.

     
  • I took a look at both of these situations and find that they are classified as warnings because they are reported as warnings by the JPEG library. Only errors result in failed processing and returning an error to the invoking environment. There are many warnings that the JPEG library can report and it is in the best position to know if a problem should be an error or a warning. If GM was to treat JPEG library warnings as errors, then many useful JPEG files would then be unrecoverable unless some other software was used.

    Probably the best that can be done is to add a new command line option to enable treating warnings as errors.

     
  • Ok, I'm fine with this solution.
    Thanks

     
    • status: open --> closed-wont-fix
     
  • It is decided that GM will report an error if libjpeg reports an error, and just a warning if libjpeg reports a warning.