United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6720240 : IOB exception when getting font metrics of hershey font

Details
Type:
Bug
Submit Date:
2008-06-27
Status:
Closed
Updated Date:
2012-10-10
Project Name:
JDK
Resolved Date:
2011-05-17
Component:
client-libs
OS:
generic
Sub-Component:
2d
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
OpenJDK6
Fixed Versions:

Related Reports
Backport:
Relates:

Sub Tasks

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



Hardware and Software, Engineered to Work Together