Author: tilman Date: Wed Jun 19 15:26:50 2024 New Revision: 1918447 URL: http://svn.apache.org/viewvc?rev=1918447&view=rev Log: PDFBOX-5843: don't fail for empty entries (e.g. zero bytes), add an empty private dict and check after the loop
Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java?rev=1918447&r1=1918446&r2=1918447&view=diff ============================================================================== --- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java (original) +++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java Wed Jun 19 15:26:50 2024 @@ -697,13 +697,6 @@ public class CFFParser DataInputByteArray fontDictInput = new DataInputByteArray(bytes); DictData fontDict = readDictData(fontDictInput); - // read private dict - DictData.Entry privateEntry = fontDict.getEntry("Private"); - if (privateEntry == null || privateEntry.size() < 2) - { - throw new IOException("Font DICT invalid without \"Private\" entry"); - } - // font dict Map<String, Object> fontDictMap = new LinkedHashMap<>(4); fontDictMap.put("FontName", getString(fontDict, "FontName")); @@ -713,6 +706,16 @@ public class CFFParser // TODO OD-4 : Add here other keys fontDictionaries.add(fontDictMap); + // read private dict + DictData.Entry privateEntry = fontDict.getEntry("Private"); + if (privateEntry == null || privateEntry.size() < 2) + { + // PDFBOX-5843 don't abort here, and don't skip empty bytes entries, because + // getLocalSubrIndex() expects subr at a specific index + privateDictionaries.add(new HashMap<>()); + continue; + } + int privateOffset = privateEntry.getNumber(1).intValue(); int privateSize = privateEntry.getNumber(0).intValue(); DictData privateDict = readDictData(input, privateOffset, privateSize); @@ -729,6 +732,11 @@ public class CFFParser privDict.put("Subrs", readIndexData(input)); } } + + if (privateDictionaries.isEmpty()) + { + throw new IOException("Font DICT invalid without \"Private\" entry"); + } // font-dict (FD) select DictData.Entry fdSelectEntry = topDict.getEntry("FDSelect");