[
https://issues.apache.org/jira/browse/PDFBOX-3641?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15882065#comment-15882065
]
Tilman Hausherr commented on PDFBOX-3641:
-----------------------------------------
{code}
public class PDFBOX3641IccTest
{
public static void main(String[] args) throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (InputStream is = new
URL("https://issues.apache.org/jira/secure/attachment/12854386/PDFBOX-3641.icc").openStream())
{
int by;
while ((by = is.read()) != -1)
{
baos.write(by);
}
}
byte[] ba = baos.toByteArray();
long t0 = System.currentTimeMillis();
for (int i = 0; i < 5000; ++i)
{
ICC_Profile profile = ICC_Profile.getInstance(ba);
ICC_ColorSpace cs = new ICC_ColorSpace(profile);
cs.toRGB(new float[cs.getNumComponents()]);
cs.fromRGB(new float[3]);
cs.toCIEXYZ(new float[cs.getNumComponents()]);
cs.fromCIEXYZ(new float[3]);
new Color(cs, new float[cs.getNumComponents()], 1f);
// if ((i % 500) == 0)
// Runtime.getRuntime().gc();
}
long duration = (System.currentTimeMillis() - t0) / 1000;
System.out.println(String.format("%d min %d sec", duration / 60,
duration % 60));
System.out.println("used memory: " +
(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) /
1000000 + " MB, max: " +
Runtime.getRuntime().maxMemory() / 1000000 + " MB");
}
}
{code}
> ICC_ColorSpace usage is not thread safe
> ---------------------------------------
>
> Key: PDFBOX-3641
> URL: https://issues.apache.org/jira/browse/PDFBOX-3641
> Project: PDFBox
> Issue Type: Bug
> Components: Rendering
> Affects Versions: 2.0.4
> Reporter: Mike Kaplinskiy
> Assignee: Tilman Hausherr
> Fix For: 2.0.5, 2.1.0
>
> Attachments: PDFBOX-3641-731495-p33-veryslow.pdf, PDFBOX-3641.icc
>
>
> Unfortunately {{ICC_ColorSpace}} is not thread safe. Even creating {{Color}}
> instances and passing an {{ICC_ColorSpace}} can't be considered thread safe.
> All color conversion calls lazy initialize a value without a memory barrier:
> https://github.com/openjdk-mirror/jdk/blob/jdk8u/jdk8u/master/src/share/classes/java/awt/color/ICC_ColorSpace.java#L172
> . This seems like a bug in Java, but PDFBox triggers it :(
> PDFBox seems to attempt to initialize colorspaces/colors in a thread-safe way
> around
> https://github.com/apache/pdfbox/blob/f419d203ebebc4deb83ba71ef0a0e6bb1ff22c5a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java#L146
> , but calls to {{toRGB}}/{{fromRGB}} aren't synchronized. I *think* calling
> all 4 (to/from)(CIEXYZ/RGB) in a locked block *should* initialize the
> instances enough to be thread safe.
> The symptoms of this problem look like this (exception formatting due to
> clojure):
> {code}
>
> org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI
> PDFRenderer.java: 94
>
> org.apache.pdfbox.rendering.PDFRenderer.renderImage
> PDFRenderer.java: 145
>
> org.apache.pdfbox.rendering.PageDrawer.drawPage
> PageDrawer.java: 189
>
> org.apache.pdfbox.contentstream.PDFStreamEngine.processPage
> PDFStreamEngine.java: 149
>
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStream
> PDFStreamEngine.java: 446
>
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators
> PDFStreamEngine.java: 472
>
> org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator
> PDFStreamEngine.java: 815
> org.apache.pdfbox.contentstream.operator.color.SetNonStrokingColorSpace.process
> SetNonStrokingColorSpace.java: 41
>
> org.apache.pdfbox.pdmodel.PDResources.getColorSpace
> PDResources.java: 166
>
> org.apache.pdfbox.pdmodel.PDResources.getColorSpace
> PDResources.java: 196
>
> org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace.create
> PDColorSpace.java: 182
>
> org.apache.pdfbox.pdmodel.graphics.color.PDICCBased.<init>
> PDICCBased.java: 89
>
> org.apache.pdfbox.pdmodel.graphics.color.PDICCBased.loadICCProfile
> PDICCBased.java: 145
>
> java.awt.Color.<init> Color.java: 542
>
> java.awt.color.ICC_ColorSpace.toRGB ICC_ColorSpace.java: 179
> java.lang.NullPointerException:
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]