Interesting PDF bugs – tiny dash values and the Java JVM

I have been looking at a PDF file which causes Java 7 to crash completely in our PDF library. So I tried on Java 6 on my Mac and it also crashed out. This is not good!

So I took the PDF file apart to see why the JVM did not like this file. The issue turns out to be a limitation in the way that Java (and it seems to effect all versions) handles a dash pattern.

In the PDF file format, you can define a line not just as a solid line but as a repeating pattern of dots, dashes and spaces. This is a GraphicsState value. It is set as 2 values with the d postscript command. So

[] 0 d gives a solid line

[3] 0 d gives a dotted line (3 on, 3 off, etc)

[2 1] 0 d gives a dotted line (2 on,1 off, etc)

It is nicely explained in the PDF reference (section 4.3)

You can actually have floating point values as well. This can be implemented in Java using the Stroke class.

The problem in the JVM appears to be that it does not like very small values. The PDF file which crashed Java has some values of 0.0187. Trial and error suggests 0.05 is a safe minimum value.

Here is our additional check and the we now have no issues 🙂

   //..loop to set dash values 

   //smaller values throw a segmentation fault in JVM
   if(dash[aa]<0.05f){
      dash[aa]=0.05f;
   }
}

//create the stroke to draw current_stroke = new BasicStroke( w,
current_line_cap_style, current_line_join_style, mitre_limit,
dash, current_line_dash_phase );

Have you come across any JVM bugs which need a simple work around?

This post is part of our “Understanding the PDF File Format” series. In each article, we discuss a PDF feature, bug, gotcha or tip. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>