#014810: ImageConversion: unexpected failure mode for corrupted jpegs

Description:

When ImageConversion is asked to scale or crop a corrupted image it causes unexpected errors. I debugged this with an older version of ImageConversion but looking at the latest code it seems that it may still be there. If this has been fixed already please excuse me.

Some jpg images have a small amount of corruption or extra bytes which most viewers ignore. When one of these slightly corrupted images is converted through GD, specifically through imagecreatefromjpeg(), it would normally throw a warning and return false.

However in ez's ImageConversion code this error is suppressed. line 77 of gd_base.php:


if ( !ezcBaseFeatures::hasFunction( $loadFunction ) || ( $handle = @$loadFunction( $file ) ) === '' )
{
    throw new ezcImageFileNotProcessableException( $file, "File could not be opened using $loadFunction." );
}

(where $loadFunction is 'imagecreatefromjpeg' in this case)

So no errors will be logged. $handle gets set to FALSE and since the code is only checking if it's equal to '', it does not enter the if statement. No exceptions are fired at this point, even though it has failed. The 'resource' var is set to FALSE. The next time getReferenceData() is called looking for 'resource' it will fail with an exception message like:

"No valid reference found for action. No resource found for the active reference"

Which is not a very useful error message since the cause is a corrupted jpeg. I would suggest that the code be changed to something more like:


$handle = @$loadFunction( $file );
if ( !ezcBaseFeatures::hasFunction( $loadFunction ) || !$handle || $handle === '' )
{
    throw new ezcImageFileNotProcessableException( $file, "File could not be opened using $loadFunction." );
}

Or it could even be more specific with additional 'if's. I've also noticed that this seems to create left over tmp image files, so perhaps close() is not being called in this error condition, but I haven't looked into that yet.

As a side note, this failure mode can also be obviated by using:


ini_set("gd.jpeg_ignore_warning", true);

Environment:

Operating System: Linux (RHEL 5)
PHP Version: 5.2.8
Database and version: mysql 5.1.31-community-log
Browser (and version): All


Steps to Reproduce:

1. Use php compiled with GD.
2. Make sure that gd.jpeg_ignore_warning is false. (default I believe)
3. Attempt to scale the attached image using ez ImageConversion tools.

Expected result:
- A scaled image or an error message and failure mode identifying a possibly corrupt jpeg.

Actual result:
- No resource is set for the handler so getReferenceData() fails with: 'No valid reference found for action. No resource found for the active reference'. PHP line number and error message have nothing to do with the actual error.


- Attachments
file_57347.jpg (239.9 kb)
[Download] [Permanent Link]
Slightly corrupted jpeg which causes failure when scaled.

- Comments

Fixed in rev. #10236.

I fixed the condition you reported in the issue, corrected the ImageMagick driver in addition and added test cases. Furthermore I added hints to the documentation how the problem of loading corrupt images with GD can be avoided.

Thanks a lot for the really good bug report! :)

#261519 by Tobias Schlitt on May 8th, 2009 [Permanent Link]

- History
Properties
Type Bug
Priority Medium
Component Components » ImageConversion
Affects 2008.2 - eZ components 2008.2
2008.2.1 - eZ components 2008.2.1
2008.2.2 - eZ components 2008.2.2
1.3.5 - ImageConversion 1.3.5
Fix Versions 2008.2.3 - eZ components 2008.2.3
2009.1alpha1 - eZ components 2009.1alpha1
Reporter Graham McNicoll
Responsible Tobias Schlitt
Status 0 Closed
Resolution Fixed
Created April 23rd, 2009
Updated May 8th, 2009
Resolved May 8th, 2009
 
Navigation [Permanent Link]
Previous Issue
Back to Issues List
Next Issue: #015537
  Graph shows to small and truncated rotated axis labels