[ 
https://issues.apache.org/jira/browse/PDFBOX-2824?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14580641#comment-14580641
 ] 

Tilman Hausherr edited comment on PDFBOX-2824 at 6/10/15 10:49 PM:
-------------------------------------------------------------------

I was able to reproduce it easier by setting cores in ParallelParametrized to 8 
and then run TestRendering (I have more files in the test directories than in 
the official build).

So I did some testing with some misc changes:

synchronized TrueTypeFont.getPath() - -no- crash
synchronized the else part in that method - crash
synchronized GlyphData getGlyph(int gid) in GlyphTable.java - crash
synchronized around "glyph = getGlyph().getGlyph(gid);" - crash
synchronized int nameToGID(String name) - crash
use a Hashtable instead of a HashMap for "tables" - crash
use a ConcurrentHashMap instead of a HashMap for "tables" - crash
synchronize everything in TrueTypeFont.getPath except the first line - -no- 
crash
set cache in Type1Glyph2D as Hashtable - crash
synchronized segment below "todo" in Type1Glyph2D.getPathForCharacterCode - 
-no- crash

-From a logical point of view, synchronizing the "todo: can this happen?" 
segment at Type1Glyph2D.getPathForCharacterCode() makes the most sense, looking 
and writing into a cache should be done carefully when in parallel. But the 
question is, did I find the real cause, or would it still happen with e.g. 32 
threads on a fast system with many similar files?-


was (Author: tilman):
I was able to reproduce it easier by setting cores in ParallelParametrized to 8 
and then run TestRendering (I have more files in the test directories than in 
the official build).

So I did some testing with some misc changes:

synchronized TrueTypeFont.getPath() - no crash
synchronized the else part in that method - crash
synchronized GlyphData getGlyph(int gid) in GlyphTable.java - crash
synchronized around "glyph = getGlyph().getGlyph(gid);" - crash
synchronized int nameToGID(String name) - crash
use a Hashtable instead of a HashMap for "tables" - crash
use a ConcurrentHashMap instead of a HashMap for "tables" - crash
synchronize everything in TrueTypeFont.getPath except the first line - no crash
set cache in Type1Glyph2D as Hashtable - crash
synchronized segment below "todo" in Type1Glyph2D.getPathForCharacterCode - no 
crash

>From a logical point of view, synchronizing the "todo: can this happen?" 
>segment at Type1Glyph2D.getPathForCharacterCode() makes the most sense, 
>looking and writing into a cache should be done carefully when in parallel. 
>But the question is, did I find the real cause, or would it still happen with 
>e.g. 32 threads on a fast system with many similar files?

> ArrayIndexOutOfBoundsException in GlyfSimpleDescript.readFlags() when 
> multithreading
> ------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-2824
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2824
>             Project: PDFBox
>          Issue Type: Bug
>          Components: FontBox
>    Affects Versions: 2.0.0
>            Reporter: Tilman Hausherr
>            Priority: Critical
>
> From Kenneth K. in the mailing list:
> I have a client application that convert pdf documents into single page tiff 
> images.  Since the user export large quantities of documents I use a 
> multithreaded approach.  Each thread loads it own document and converts the 
> pages one by one.
> The pdf file is serialized to the client thread and then each thread executes 
> the following code.  If I only use 1 thread there is no problem.  I checked 
> to make sure objects are shared between threads.
> {code}
>             docin = PDDocument.load(new 
> ByteArrayInputStream(documentResult.getImage().getContent()),true);
>             if(null==docin)
>               throw new Exception("Invalid PDF document or an occured during 
> retrieval");
>                int numPages = docin.getNumberOfPages();
>                      String strPath = getPath(numPages);
>                      int iPage = 0;
>             PDFRenderer renderer = new PDFRenderer(docin);
>             for (int i=0;i<numPages;i++)
>             {
>               PDPage page = docin.getPage(i);
>               PDRectangle rect = page.getMediaBox();
>               BufferedImage pageImage = null;
>               pageImage = renderer.renderImageWithDPI(i, 200f, 
> ImageType.BINARY);
>               ...
>             }
> {code}
> {code}
> Array index out of range: 8
>        at 
> org.apache.fontbox.ttf.GlyfSimpleDescript.readFlags(GlyfSimpleDescript.java:202)
>        at 
> org.apache.fontbox.ttf.GlyfSimpleDescript.<init>(GlyfSimpleDescript.java:77)
>        at org.apache.fontbox.ttf.GlyphData.initData(GlyphData.java:58)
>        at org.apache.fontbox.ttf.GlyphTable.getGlyph(GlyphTable.java:161)
>        at 
> org.apache.pdfbox.rendering.TTFGlyph2D.getPathForGID(TTFGlyph2D.java:140)
>        at 
> org.apache.pdfbox.rendering.TTFGlyph2D.getPathForCharacterCode(TTFGlyph2D.java:92)
>        at 
> org.apache.pdfbox.rendering.PageDrawer.drawGlyph2D(PageDrawer.java:333)
>        at 
> org.apache.pdfbox.rendering.PageDrawer.showFontGlyph(PageDrawer.java:314)
>        at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph(PDFStreamEngine.java:731)
>        at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.showText(PDFStreamEngine.java:690)
>        at org.apache.pdfbox.rendering.PageDrawer.showText(PageDrawer.java:296)
>        at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.showTextStrings(PDFStreamEngine.java:600)
>        at 
> org.apache.pdfbox.contentstream.operator.text.ShowTextAdjusted.process(ShowTextAdjusted.java:38)
>        at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:802)
>        at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:464)
>        at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:438)
>        at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:149)
>        at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:179)
>        at 
> org.apache.pdfbox.rendering.PDFRenderer.renderPage(PDFRenderer.java:205)
>        at 
> org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:136)
>        at 
> org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:95)
>        at 
> org.ilsos.cm.export.client.rmi.workers.Pdf2SinglePageTiff.processResult(Pdf2SinglePageTiff.java:142)
>        at 
> org.ilsos.cm.export.client.rmi.ExportWorker.run(ExportWorker.java:72)
>        at java.lang.Thread.run(Thread.java:784)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to