Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4413118

Font.createFont leaks files and does not work sandboxed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.0
    • client-libs
    • None
    • 2d
    • x86
    • windows_nt



      The following piece of code has two problems:

      1) requires write permission does not work sandboxed (applet or
         Java Web Start)

         Fix: A doPriviledge needs to be put into the code

      2) leaks a file every time it is called (in C:\Temp on Windows and
         /usr/tmp on Solaris)

         Fix: Make sure to remove the file. This is a serious problem
         since a new file is leaked everytime the application is started



      //---------------------------------------------------------------------

      import java.awt.*;
      import java.io.*;
      import java.net.*;

      public class ybGuiFactory
      {

      ...

          private final static String VAR_FONT_FILE = "YB_VAR_FONT.TTF";

      ...

          public static void loadVarFont(String servletURL)
          {
              ClassLoader cl = ybGuiFactory.class.getClassLoader();
              try {
                  // load from jar file
                  InputStream fontStream =
      cl.getResourceAsStream("fonts/"+VAR_FONT_FILE);
                  if(fontStream == null) {
                    // load over the net
                    URL fontURL = new URL(servletURL+"fonts/"+VAR_FONT_FILE);
                    fontStream = fontURL.openStream();
                    if(fontStream == null) return;
                  }
                  Font f = Font.createFont(Font.TRUETYPE_FONT, new
      BufferedInputStream(fontStream));
                  VAR_FONT = f.deriveFont((float) 8.8);
                  fontStream.close();
              }
              catch(IOException ioe) {
                  ioe.printStackTrace();
                  return;
              }
              catch(FontFormatException ffe) {
                  ffe.printStackTrace();
                  return;
              }
          }

      ...

      }

      //---------------------------------------------------------------

      --
      rene.schmidt@eng 2001-02-07

            Unassigned Unassigned
            rschmidtsunw Rene Schmidt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: