Author: toad
Date: 2006-12-02 16:42:54 +0000 (Sat, 02 Dec 2006)
New Revision: 11194

Modified:
   trunk/freenet/src/freenet/clients/http/filter/PNGFilter.java
Log:
Always close

Modified: trunk/freenet/src/freenet/clients/http/filter/PNGFilter.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/filter/PNGFilter.java        
2006-12-02 16:40:52 UTC (rev 11193)
+++ trunk/freenet/src/freenet/clients/http/filter/PNGFilter.java        
2006-12-02 16:42:54 UTC (rev 11194)
@@ -29,18 +29,22 @@
                InputStream is = data.getInputStream();
                BufferedInputStream bis = new BufferedInputStream(is);
                DataInputStream dis = new DataInputStream(bis);
-               // Check the header
-               byte[] headerCheck = new byte[pngHeader.length];
-               dis.read(headerCheck);
-               if(!Arrays.equals(headerCheck, pngHeader)) {
-                       // Throw an exception
-                       String message = "The file you tried to fetch is not a 
PNG. It does not include a valid PNG header. "+
+               try {
+                       // Check the header
+                       byte[] headerCheck = new byte[pngHeader.length];
+                       dis.read(headerCheck);
+                       if(!Arrays.equals(headerCheck, pngHeader)) {
+                               // Throw an exception
+                               String message = 
+                                       "The file you tried to fetch is not a 
PNG. It does not include a valid PNG header. "+
                                        "It might be some other file format, 
and your browser may do something horrible with it, "+
                                        "therefore we have blocked it."; 
-                       throw new DataFilterException("Not a PNG - invalid 
header", "Not a PNG - invalid header",
-                                       "<p>"+message+"</p>", new 
HTMLNode("p").addChild("#", message));
+                               throw new DataFilterException("Not a PNG - 
invalid header", "Not a PNG - invalid header",
+                                               "<p>"+message+"</p>", new 
HTMLNode("p").addChild("#", message));
+                       }
+               } finally {
+                       dis.close();
                }
-               dis.close();
                return data;
        }



Reply via email to