JDK-4376103 : Java hangs rendering a shape with max. coordinates much greater than 32K
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.2.0,1.2.2,1.3.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,solaris_2.5.1,solaris_8,windows_nt generic,solaris_2.5.1,solaris_8,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 2000-10-03
  • Updated: 2001-03-26
  • Resolved: 2001-03-26
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 Availability Release.

To download the current JDK release, click here.
Other
1.4.0 betaFixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
/**
 * 
 * Demonstrate Java hang when rendering a Shape with max. coordinates
 * much greater than 32K.
 *
 * Item 16
 * 10/3/2000
 * 
 * 
 * Displaying a Shape in Graphics2D with coordinates much greater than 32K
 * using the default transform and clip causes Java to hang.
 * 
 * The problem occurs under WinNT 4.0, Win95, Win98, and Solaris 8 iwth
 * the 1.2.2 and 1.3 JVMs.
 * 
 * The program below draws a Shape which is a triangle, and the sole
 * command line argument is a number used as the maximum x and y
 * coordinates  of the triangle.
 * 
 * In other words it draws a filled triangle with coordinates:  (0,0),
 * (0,n), (n,n)
 * 
 * 33052 may be a magic number for this problem on Solaris.vi
 * 
 *
 * 
 * To reproduce: 
 *     javac gifclient/ClipBugViewer.java
 * 
 *     java gifclient.ClipBugViewer 64000
 */
package gifclient;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;

/** demonstrate clipping bug
 */
public class ClipBugViewer extends JPanel {

	private Shape m_shape;

	public ClipBugViewer()
	{
	}

	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);

		Graphics2D g2d = (Graphics2D) g;
		if (m_shape != null)
		{
			System.out.println("paintComponent()");
			g2d.setColor(Color.blue);
			System.out.println("paintComponent() about to draw");
			g2d.draw(m_shape);
			System.out.println("paintComponent() about to fill");
			g2d.fill(m_shape);
			System.out.println("paintComponent() returning");
		}

	}

	public void setShape(Shape shape)
	{
		m_shape = shape;
	}

	public static final void main(String [] args) throws Exception
	{
		int bound = 32000;
		if (args.length > 0)
		  try {
			bound = Integer.parseInt(args[0]);
		  } catch (NumberFormatException e) {
			System.err.println("Usage: ClipBugViewer <#>" + 
				"	Supply an upper bound, default is 32000");
		  };
		ClipBugViewer viewer = new ClipBugViewer();
		viewer.setSize(new Dimension(600, 600));

		JFrame frame = new JFrame();
		frame.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e) 
			{
				System.exit(0);
			}
		});
		
		GeneralPath path = new GeneralPath();
		path.moveTo(0, 0);
		path.lineTo(0, bound);
		path.lineTo(0 + bound, bound);

		path.closePath();

		viewer.setShape(path);
			
		frame.setSize(new Dimension(600, 600));
		frame.setVisible(true);
		frame.getContentPane().add(viewer);

		frame.repaint();
	}
}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta FIXED IN: merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

EVALUATION This is going into an infinite loop in the clipping code. When the code tries to determine where the line segment intersects the clipping rectangle the math involves performing a multiply on the coordinates and the result overflows a 32-bit integer leaving the code with essentially a random new endpoint that must again be clipped as it is most likely outside the clip rectangle again. The code needs to test the coordinates for being inside 16-bits and switch to long 64-bit arithmetic if needed. jim.graham@Eng 2001-03-06
06-03-2001