JDK-6568541 : Very large font size causes SIGSEGV when FontMetrics.stringWidth() invoked
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2007-06-12
  • Updated: 2011-02-16
  • Resolved: 2007-06-14
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Server VM (build 1.6.0_01-b06, mixed mode)


FULL OS VERSION :
Linux speedy 2.6.20.1mjs #3 SMP Mon May 14 11:22:25 CDT 2007 x86_64 x86_64 x86_64 GNU/Linux
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Calling FontMetrics.stringWidth(string) after setting a very large font size (e.g. 32000) causes the Java VM to crash with a SIGSEGV. Interestingly, larger numbers (e.g. 50000) do not cause the crash.

THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program

EXPECTED VERSUS ACTUAL BEHAVIOR :
  Program should print out a number (-53695 on 1.5.0_11).

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Attached seperatly

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;

import javax.swing.JFrame;


public class TestBug extends JFrame {

	public TestBug() {
		}
	public void test() {
		
		Font f=new Font("culfont",Font.PLAIN,30000);
	
		Graphics2D g=(Graphics2D) this.getGraphics();
		
		g.setFont(f);
		FontMetrics fm=g.getFontMetrics();
		String string="LAKE";
			
		int length=fm.stringWidth(string);
		System.out.println("Size: "+length);


			
		
	}

public static void main(String[] args) {
	TestBug tb=new TestBug();
	tb.setVisible(true);
	tb.test();

}

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Make sure the application doesn't use excessively large font size. This actually demonstrated a bug in my application, but the VM should handle it gracefully.

Comments
EVALUATION This is a duplicate of 6533413: REGRESSION:JEudlid bean crashes with font sizes 180 and greater That is fixed in 6u2 and the program no longer crashes and prints out a value. This is because we no longer actually rasterise the glyph, so less T2K code is excercised. However the value is nonsensical, so the metrics obtained from the rasteriser show symptoms of overflow. We have already have reports of that problem: 4522900: Bad Font Metrics returned (ascent, descent) when using scaled fonts in Java2D 6313761: FontMetrics.getStringBounds() floating point overflow problems
14-06-2007