You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2022/06/16 16:17:54 UTC

svn commit: r1901984 - /pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java

Author: tilman
Date: Thu Jun 16 16:17:54 2022
New Revision: 1901984

URL: http://svn.apache.org/viewvc?rev=1901984&view=rev
Log:
PDFBOX-5460: avoid deadlock

Modified:
    pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java

Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java?rev=1901984&r1=1901983&r2=1901984&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphTable.java Thu Jun 16 16:17:54 2022
@@ -39,6 +39,8 @@ public class GlyphTable extends TTFTable
     
     private int cached = 0;
     
+    private HorizontalMetricsTable hmt = null;
+    
     /**
      * Don't even bother to cache huge fonts.
      */
@@ -75,6 +77,12 @@ public class GlyphTable extends TTFTable
 
         // we don't actually read the complete table here because it can contain tens of thousands of glyphs
         this.data = data;
+
+        // PDFBOX-5460: read hmtx table early to avoid deadlock if getGlyph() locks "data"
+        // and then locks TrueTypeFont to read this table, while another thread
+        // locks TrueTypeFont and then tries to lock "data"
+        hmt = font.getHorizontalMetrics();
+
         initialized = true;
     }
 
@@ -207,7 +215,6 @@ public class GlyphTable extends TTFTable
     private GlyphData getGlyphData(int gid) throws IOException
     {
         GlyphData glyph = new GlyphData();
-        HorizontalMetricsTable hmt = font.getHorizontalMetrics();
         int leftSideBearing = hmt == null ? 0 : hmt.getLeftSideBearing(gid);
         glyph.initData(this, data, leftSideBearing);
         // resolve composite glyph