Comment 47 for bug 913434

Revision history for this message
In , Peterwcostello (peterwcostello) wrote :

This is a multi-threading problem with LCMS version 2.5. It was claimed to have been fixed with LCMS v2.6, but many OS are still running the older packages. I have code that parses PDF files. It is running in a production environment on random PDF files and with lots of threads. I was able to stop the error (~2 years ago) by adding "syncronized" keyword around the following block of java code:
   ICC_Profile profile = ICC_Profile.getInstance(byte[]);
   ICC_ColorSpace colorSpace = new ICC_ColorSpace(profile);
   int numComponents = 3; // From PDF dictionary, typically '3' (RGB).
   float[] components = new float[numComponents];

   // Test that ICC_Profile can be parsed
   // Generates an exception on malformed byte[]
   // Crashes JVM sporadically if not forced inline by 'syncronized'
   new java.awt.Color(colorSpace,components,1f);

If it helps, here's my java method (won't compile as it is missing methods):
 public static synchronized PDFColorSpace getICCColorSpace(PDFToken dict) throws IOException {
  PDFColorSpace cs=null;
  PDFToken nToken = dict.getDictionaryItem(N);
  int numComponents = (nToken==null) ? 1 : nToken.getInteger();

  try {

   ICC_Profile profile = ICC_Profile.getInstance(dict.getStream().toString8().getBytes());

   // This does not prevent JVM Crash with BELL.SW
   // if (profile.getNumComponents() == numComponents) ...

   ICC_ColorSpace colorSpace = new ICC_ColorSpace(profile);
   cs = new NativeColorSpace(TypeICC,colorSpace);

   // Test if ICC_Profile is OK. Will throw Exception (or even crash the JVM)
   // eg: Cik#99001898, http://www.siemens.com/investor/pool/de/investor_relations/events/hauptversammlung/2012/dividendenbekanntmachung.pdf, pg0
   // eg: JVM Crash, Cik#99002137, BELL.SW
   float[] components = new float[numComponents];
   new java.awt.Color(colorSpace,components,1f);

  } catch (Exception e) {
   cs=null;
  }
        return cs;
      }