Author: tilman
Date: Wed Jun 19 15:26:45 2024
New Revision: 1918446

URL: http://svn.apache.org/viewvc?rev=1918446&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/branches/3.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java

Modified: 
pdfbox/branches/3.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/3.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java?rev=1918446&r1=1918445&r2=1918446&view=diff
==============================================================================
--- 
pdfbox/branches/3.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java 
(original)
+++ 
pdfbox/branches/3.0/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java 
Wed Jun 19 15:26:45 2024
@@ -696,13 +696,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"));
@@ -712,6 +705,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);
@@ -728,6 +731,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");


Reply via email to