JDK-6720240 : IOB exception when getting font metrics of hershey font
  • Type: Bug
  • Status: Closed
  • Resolution: Fixed
  • Component: client-libs
  • Sub-Component: 2d
  • Priority: P2
  • Affected Version: OpenJDK6
  • OS: generic
  • CPU: generic
  • Submit Date: 2008-06-27
  • Updated Date: 2012-10-10
  • Resolved Date: 2011-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 7
7 b33Fixed
Related Reports
Relates :  
Description
The following code throws exception with hershey font that can be found in recent 
fedora release:
            
  Font f = Font.createFont(Font.TYPE1_FONT, new File("hrger.pfa"));
  FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
  fm.getWidths(); //Index out of bounds is thrown here.

Exception stack trace:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
        at sun.font.FileFontStrike.setCachedGlyphPtr(FileFontStrike.java:374)
        at sun.font.FileFontStrike.setCachedGlyphPtr(FileFontStrike.java:425)
        at sun.font.FileFontStrike.getGlyphImagePtr(FileFontStrike.java:284)
        at sun.font.FileFontStrike.getGlyphAdvance(FileFontStrike.java:496)
        at sun.font.FileFontStrike.getCodePointAdvance(FileFontStrike.java:526)
        at sun.font.FontDesignMetrics.handleCharWidth(FontDesignMetrics.java:415)
        at sun.font.FontDesignMetrics.getWidths(FontDesignMetrics.java:537)
        at HersheyFont.main(HersheyFont.java:27)


Test source code and font file are attached to this CR.

This can be reproduced on openjdk 6 "build 1.6.0-ea-b10" on at least 
solaris x86 and linux.
 

on jdk 7 the test code above runs successfully on both solaris and linux.

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/java2d_data/7/6720240.0
2008-07-15

EVALUATION Problem is reproducible with freetype version of build only. T2K works just fine. Further analysis shown that simple freetype program that only initializes freetype library and tries to create font face for thhis font file fails with error code 3. This means "invalid file format" according to fterrdef.h I.e. the reason why font is considered to be malformed is inside freetype (and may be even resolved in the newer version of library or perhaps this is build issue). It is NOT inside JDK codebase and we can not fix it to accept this font. However, we still need to fix NullScaler used as substitute for bad fonts to report it contains 1 glyph (missing glyph) to avoid ArrayIndexOutOfBoundException. (and this needs to be fixed in both JDK 7 and 6-open)
2008-07-10

EVALUATION Reassigned to Java2D team.
2008-06-30

EVALUATION I *suspect* that reason for exceptions and solution are covered by 6609143. (need to update NullFontScaler to return 1 as number of glyphs). However, i can not reproduce this problem with your testcase on my windows using jdk7 (build both with freetype and t2k) and this problem is NOT fixed there. It is possible that only freetype is failing on this font and t2k works with it. But still, it should not be platform dependent and should fail on other platforms using same font for both 6-open and 7. Ned further investigation.
2008-06-30