Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4219

Multithreading problem when rendering several documents with Standard 14 fonts

    XMLWordPrintableJSON

Details

    Description

      I get rendering errors and sometimes exceptions in my regression tests. It is somehow related to several threads initializing standard 14 fonts. It happens only about every 25 times in a test program I created. That one renders 2 files in 4 threads and compares the result with the existing result.

      My theory is that one thread accesses the naming table and another accesses the glyf table, and both change the stream position. I tried several things in the last months to avoid it, all were unsuccessful and I lost my notes about it last winter due to a static discharge on a usb stick. (Thank you KINGSTON!)

      Here's the output when it doesn't go well:

      11.05.2018 10:54:26.322 WARN  [pool-1-thread-4] org.apache.pdfbox.pdmodel.font.PDType1Font:296 - Using fallback font TimesNewRomanPS-BoldMT for Galliard-Bold
      11.05.2018 10:54:26.323 WARN  [pool-1-thread-2] org.apache.pdfbox.pdmodel.font.PDType1Font:296 - Using fallback font TimesNewRomanPS-BoldMT for Galliard-Bold
      11.05.2018 10:54:26.386 WARN  [pool-1-thread-2] org.apache.pdfbox.pdmodel.font.PDType1Font:296 - Using fallback font TimesNewRomanPSMT for Galliard-Roman
      11.05.2018 10:54:26.421 WARN  [pool-1-thread-4] org.apache.pdfbox.pdmodel.font.PDType1Font:296 - Using fallback font TimesNewRomanPSMT for Galliard-Roman
      11.05.2018 10:54:26.697 WARN  [pool-1-thread-2] org.apache.pdfbox.pdmodel.font.PDType1Font:296 - Using fallback font TimesNewRomanPS-ItalicMT for Galliard-Italic
      11.05.2018 10:54:26.818 WARN  [pool-1-thread-4] org.apache.pdfbox.pdmodel.font.PDType1Font:296 - Using fallback font TimesNewRomanPS-ItalicMT for Galliard-Italic
      C:\Users\XXX\Documents\Java\PDFBox reactor\pdfbox\src\test\resources\input\rendering\166292-fi-ligature.pdf
      oh oh
      C:\Users\XXX\Documents\Java\PDFBox reactor\pdfbox\src\test\resources\input\rendering\166292-fi-ligature.pdf
      oh oh
      C:\Users\XXX\Documents\Java\PDFBox reactor\pdfbox\src\test\resources\input\rendering\014261-p3-ccitt.pdf
      oh oh
      C:\Users\XXX\Documents\Java\PDFBox reactor\pdfbox\src\test\resources\input\rendering\014261-p3-ccitt.pdf
      oh oh
      done
      

      Sometimes in the past I got exceptions:

      Exception in thread "Thread-2" java.lang.RuntimeException: java.io.IOException: Unexpected end of TTF stream reached
      	at pdfboxpageimageextraction.MulithreadTest.run(MulithreadTest.java:87)
      Caused by: java.io.IOException: Unexpected end of TTF stream reached
      	at org.apache.fontbox.ttf.TTFDataStream.read(TTFDataStream.java:274)
      	at org.apache.fontbox.ttf.TTFDataStream.readString(TTFDataStream.java:91)
      	at org.apache.fontbox.ttf.NamingTable.read(NamingTable.java:113)
      	at org.apache.fontbox.ttf.TrueTypeFont.readTable(TrueTypeFont.java:373)
      	at org.apache.fontbox.ttf.TrueTypeFont.getTable(TrueTypeFont.java:163)
      	at org.apache.fontbox.ttf.TrueTypeFont.getNaming(TrueTypeFont.java:179)
      	at org.apache.fontbox.ttf.TrueTypeFont.getName(TrueTypeFont.java:471)
      	at org.apache.pdfbox.pdmodel.font.PDType1Font.<init>(PDType1Font.java:296)
      	at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:62)
      	at org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:143)
      	at org.apache.pdfbox.contentstream.operator.text.SetFontAndSize.process(SetFontAndSize.java:60)
      	at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:853)
      	at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:506)
      	at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:478)
      	at org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:156)
      	at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:258)
      	at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:225)
      	at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:164)
      

      Sometimes I get an AIOOBE:

      Exception in thread "Thread-1" java.lang.ArrayIndexOutOfBoundsException
      	at org.apache.fontbox.ttf.BufferedRandomAccessFile.read(BufferedRandomAccessFile.java:158)
      	at org.apache.fontbox.ttf.RAFDataStream.read(RAFDataStream.java:167)
      	at org.apache.fontbox.ttf.TTFDataStream.read(TTFDataStream.java:264)
      	at org.apache.fontbox.ttf.TTFDataStream.readString(TTFDataStream.java:91)
      	at org.apache.fontbox.ttf.NamingTable.read(NamingTable.java:113)
      	at org.apache.fontbox.ttf.TrueTypeFont.readTable(TrueTypeFont.java:373)
      	at org.apache.fontbox.ttf.TrueTypeFont.getTable(TrueTypeFont.java:163)
      	at org.apache.fontbox.ttf.TrueTypeFont.getNaming(TrueTypeFont.java:179)
      	at org.apache.fontbox.ttf.TrueTypeFont.getName(TrueTypeFont.java:471)
      	at org.apache.pdfbox.pdmodel.font.PDType1Font.<init>(PDType1Font.java:296)
      	at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:62)
      	at org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:143)
      	at org.apache.pdfbox.contentstream.operator.text.SetFontAndSize.process(SetFontAndSize.java:60)
      	at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:853)
      	at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:506)
      	at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:478)
      	at org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:156)
      	at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:258)
      	at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:225)
      	at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:164)
      

      Attachments

        1. 014261-p3-ccitt.pdf
          104 kB
          Tilman Hausherr
        2. 014261-p3-ccitt.pdf-1.png
          181 kB
          Tilman Hausherr
        3. 014261-p3-ccitt.pdf-1-bad1.png
          199 kB
          Tilman Hausherr
        4. 014261-p3-ccitt.pdf-1-bad2.png
          181 kB
          Tilman Hausherr
        5. 014261-p3-ccitt.pdf-1-bad3.png
          73 kB
          Tilman Hausherr
        6. 166292-fi-ligature.pdf
          39 kB
          Tilman Hausherr
        7. 166292-fi-ligature.pdf-1.png
          323 kB
          Tilman Hausherr
        8. 166292-fi-ligature.pdf-1-bad1.png
          341 kB
          Tilman Hausherr
        9. 166292-fi-ligature.pdf-1-bad2.png
          324 kB
          Tilman Hausherr
        10. 166292-fi-ligature.pdf-1-bad3.png
          210 kB
          Tilman Hausherr
        11. MulithreadTest.java
          3 kB
          Tilman Hausherr

        Issue Links

          Activity

            People

              tilman Tilman Hausherr
              tilman Tilman Hausherr
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: