xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spepp...@apache.org
Subject svn commit: r454331 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java
Date Mon, 09 Oct 2006 10:34:33 GMT
Author: spepping
Date: Mon Oct  9 03:34:32 2006
New Revision: 454331

URL: http://svn.apache.org/viewvc?view=rev&rev=454331
Log:
Prevent a StringIndexOutOfBoundsException when the PNG output file
name does not have an extension. Patch submitted by Matt Healy <mjh at
cs dot rit dot edu>, see bug 40655.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java?view=diff&rev=454331&r1=454330&r2=454331
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/bitmap/PNGRenderer.java Mon Oct 
9 03:34:32 2006
@@ -48,6 +48,9 @@
     /** The MIME type for png-Rendering */
     public static final String MIME_TYPE = MimeConstants.MIME_PNG;
 
+    /** The file extension expected for PNG files */
+    private static final String PNG_FILE_EXTENSION = "png";
+
     /** The file syntax prefix, eg. "page" will output "page1.png" etc */
     private String filePrefix;
 
@@ -71,10 +74,15 @@
 
     /**
      * Sets the output directory, either from the outfile specified on the
-     * command line, or from the directory specified in configuration file. Also
-     * sets the file name syntax, eg. "page"
+     * command line, or from the directory specified in configuration file.
+     * Also sets the file name syntax, eg. "page".
+     * The file name must not have an extension, or must have extension "png",
+     * and its last period must not be at the start (empty file prefix).
+     * 
+     * @throws IOException if an invalid output file name was specified
+     *                     (e.g., with an extension other than '.png')
      */
-    private void setOutputDirectory() {
+    private void setOutputDirectory() throws IOException {
 
         // the file provided on the command line
         File f = getUserAgent().getOutputFile();
@@ -88,12 +96,24 @@
             // extracting file name syntax
             String s = f.getName();
             int i = s.lastIndexOf(".");
+            if (i > 0) {
+                // Make sure that the file extension was "png"
+                String extension = s.substring(i + 1).toLowerCase();
+                if (!PNG_FILE_EXTENSION.equals(extension)) {
+                    throw new IOException("Invalid file extension ('"
+                                          + extension + "') specified");
+                }
+            } else if (i == -1) {
+                i = s.length();
+            } else { // i == 0
+                throw new IOException("Invalid file name ('"
+                                      + s + "') specified");
+            }
             if (s.charAt(i - 1) == '1') {
                 i--; // getting rid of the "1"
             }
             filePrefix = s.substring(0, i);
         }
-
     }
 
     /** @see org.apache.fop.render.Renderer#stopRenderer() */
@@ -147,7 +167,7 @@
             return null;
         } else {
             File f = new File(outputDir,
-                    filePrefix + (pageNumber + 1) + ".png");
+                    filePrefix + (pageNumber + 1) + "." + PNG_FILE_EXTENSION);
             try {
                 OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
                 return os;



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message