]> source.dussan.org Git - poi.git/commitdiff
[bug-65639] increase max size of HSLF font data and try to cache the FontHeader instance
authorPJ Fanning <fanningpj@apache.org>
Thu, 21 Oct 2021 10:08:35 +0000 (10:08 +0000)
committerPJ Fanning <fanningpj@apache.org>
Thu, 21 Oct 2021 10:08:35 +0000 (10:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894438 13f79535-47bb-0310-9956-ffa450edef68

poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEmbeddedData.java

index b9acb2e3bf66e21d8c9b6227ff5ff6009be35f7f..b27cdb4b53494b2585a5bb73204f872b68f6bd0e 100644 (file)
@@ -31,8 +31,8 @@ import org.apache.poi.util.LittleEndian;
 
 @SuppressWarnings("WeakerAccess")
 public class FontEmbeddedData extends RecordAtom implements FontFacet {
-    //arbitrarily selected; may need to increase
-    private static final int MAX_RECORD_LENGTH = 1_000_000;
+    //arbitrarily selected; may need to increase (increased due to https://bz.apache.org/bugzilla/show_bug.cgi?id=65639)
+    private static final int MAX_RECORD_LENGTH = 5_000_000;
 
     /**
      * Record header.
@@ -44,6 +44,11 @@ public class FontEmbeddedData extends RecordAtom implements FontFacet {
      */
     private byte[] _data;
 
+    /**
+     * A cached FontHeader so that we don't keep creating new FontHeader instances
+     */
+    private FontHeader fontHeader;
+
     /**
      * Constructs a brand new font embedded record.
      */
@@ -87,14 +92,18 @@ public class FontEmbeddedData extends RecordAtom implements FontFacet {
     }
 
     public void setFontData(byte[] fontData) {
+        fontHeader = null;
         _data = fontData.clone();
         LittleEndian.putInt(_header, 4, _data.length);
     }
 
     public FontHeader getFontHeader() {
-        FontHeader h = new FontHeader();
-        h.init(_data, 0, _data.length);
-        return h;
+        if (fontHeader == null) {
+            FontHeader h = new FontHeader();
+            h.init(_data, 0, _data.length);
+            fontHeader = h;
+        }
+        return fontHeader;
     }
 
     @Override