From: PJ Fanning Date: Thu, 21 Oct 2021 10:08:35 +0000 (+0000) Subject: [bug-65639] increase max size of HSLF font data and try to cache the FontHeader instance X-Git-Tag: REL_5_2_0~341 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fa00e7d472eafd6354e77b43c3668cd205f857a3;p=poi.git [bug-65639] increase max size of HSLF font data and try to cache the FontHeader instance git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894438 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEmbeddedData.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEmbeddedData.java index b9acb2e3bf..b27cdb4b53 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEmbeddedData.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEmbeddedData.java @@ -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