You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by je...@apache.org on 2008/03/07 11:09:41 UTC

svn commit: r634596 - in /xmlgraphics/commons/trunk: ./ src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ src/java/org/apache/xmlgraphics/image/loader/util/ test/images/ test/java/org/apache/xmlgraphics/image/loader/

Author: jeremias
Date: Fri Mar  7 02:09:20 2008
New Revision: 634596

URL: http://svn.apache.org/viewvc?rev=634596&view=rev
Log:
Fixed behaviour for the cases where a corrupt PNG image is encountered.

Added:
    xmlgraphics/commons/trunk/test/images/corrupt-image.png   (with props)
    xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java   (with props)
Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/PreloaderImageIO.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/util/ImageUtil.java
    xmlgraphics/commons/trunk/status.xml

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/PreloaderImageIO.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/PreloaderImageIO.java?rev=634596&r1=634595&r2=634596&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/PreloaderImageIO.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/PreloaderImageIO.java Fri Mar  7 02:09:20 2008
@@ -57,6 +57,7 @@
             return null;
         }
 
+        IOException firstIOException = null;
         IIOMetadata iiometa = null;
         ImageSize size = null;
         String mime = null;
@@ -73,10 +74,25 @@
                 mime = reader.getOriginatingProvider().getMIMETypes()[0];
                 break;
             } catch (IOException ioe) {
-                //ignore and continue
+                //remember the first exception, ignore all others and continue
+                if (firstIOException == null) {
+                    firstIOException = ioe;
+                }
             } finally {
                 reader.dispose();
                 in.reset();
+            }
+        }
+        
+        if (iiometa == null) {
+            if (firstIOException == null) {
+                throw new ImageException("Could not extract image metadata");
+            } else {
+                throw new ImageException("I/O error while extracting image metadata"
+                        + (firstIOException.getMessage() != null
+                            ? ": " + firstIOException.getMessage()
+                            : ""),
+                        firstIOException);
             }
         }
         

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/util/ImageUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/util/ImageUtil.java?rev=634596&r1=634595&r2=634596&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/util/ImageUtil.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/util/ImageUtil.java Fri Mar  7 02:09:20 2008
@@ -23,6 +23,7 @@
 import java.io.InputStream;
 import java.io.Reader;
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.net.URI;
@@ -241,7 +242,11 @@
                         String methodName = method.getName();
                         //Ignore calls to flush*()
                         if (!methodName.startsWith("flush")) {
-                            return method.invoke(in, args);
+                            try {
+                                return method.invoke(in, args);
+                            } catch (InvocationTargetException ite) {
+                                throw ite.getCause();
+                            }
                         } else {
                             return null;
                         }

Modified: xmlgraphics/commons/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/status.xml?rev=634596&r1=634595&r2=634596&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/status.xml (original)
+++ xmlgraphics/commons/trunk/status.xml Fri Mar  7 02:09:20 2008
@@ -41,6 +41,9 @@
   <changes>
     <release version="Trunk" date="n/a">
       <action context="Code" dev="JM" type="fix">
+        Fixed behaviour for the cases where a corrupt PNG image is encountered.
+      </action>
+      <action context="Code" dev="JM" type="fix">
         Bugfix for EOFException when pre-loading very small PNG images (file size &lt; 88 bytes).
       </action>
     </release>

Added: xmlgraphics/commons/trunk/test/images/corrupt-image.png
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/images/corrupt-image.png?rev=634596&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/commons/trunk/test/images/corrupt-image.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java?rev=634596&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java Fri Mar  7 02:09:20 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.image.loader;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for error behaviour with corrupt images.
+ */
+public class CorruptImagesTestCase extends TestCase {
+
+    private MockImageContext imageContext = MockImageContext.getInstance();
+    
+    public CorruptImagesTestCase(String name) {
+        super(name);
+    }
+    
+    public void testCorruptPNG() throws Exception {
+        String uri = "corrupt-image.png";
+        
+        ImageSessionContext sessionContext = imageContext.newSessionContext();
+        ImageManager manager = imageContext.getImageManager();
+        
+        try {
+            manager.preloadImage(uri, sessionContext);
+            fail("Expected an ImageException!");
+        } catch (ImageException ie) {
+            //Expected exception
+            assertNotNull(ie.getMessage());
+        }
+    }
+    
+}

Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
Apache XML Graphics Project URL: http://xmlgraphics.apache.org/
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org