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 2020/07/26 15:04:21 UTC

svn commit: r1880329 - in /pdfbox/trunk/fontbox/src: main/java/org/apache/fontbox/cmap/CodespaceRange.java test/java/org/apache/fontbox/cmap/TestCodespaceRange.java

Author: tilman
Date: Sun Jul 26 15:04:21 2020
New Revision: 1880329

URL: http://svn.apache.org/viewvc?rev=1880329&view=rev
Log:
PDFBOX-4923: enlarge startValue array if it is 0, e.g. in "1 begincodespacerange <00> <ffff> endcodespacerange"

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java
    pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCodespaceRange.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java?rev=1880329&r1=1880328&r2=1880329&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/cmap/CodespaceRange.java Sun Jul 26 15:04:21 2020
@@ -35,19 +35,26 @@ public class CodespaceRange
      * &lt;8140&gt; to &lt;9FFC&gt; defines a rectangular range. The high byte has to be within 0x81 and 0x9F and the low
      * byte has to be within 0x40 and 0xFC
      * 
+     * @param startBytes
+     * @param endBytes
      */
     public CodespaceRange(byte[] startBytes, byte[] endBytes)
     {
-        if (startBytes.length != endBytes.length)
+        byte[] correctedStartBytes = startBytes;
+        if (startBytes.length != endBytes.length && startBytes.length == 1 && startBytes[0] == 0)
+        {
+            correctedStartBytes = new byte[endBytes.length];
+        }
+        else if (startBytes.length != endBytes.length)
         {
             throw new IllegalArgumentException(
                     "The start and the end values must not have different lengths.");
         }
-        start = new int[startBytes.length];
+        start = new int[correctedStartBytes.length];
         end = new int[endBytes.length];
-        for (int i = 0; i < startBytes.length; i++)
+        for (int i = 0; i < correctedStartBytes.length; i++)
         {
-            start[i] = startBytes[i] & 0xFF;
+            start[i] = correctedStartBytes[i] & 0xFF;
             end[i] = endBytes[i] & 0xFF;
         }
         codeLength = endBytes.length;

Modified: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCodespaceRange.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCodespaceRange.java?rev=1880329&r1=1880328&r2=1880329&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCodespaceRange.java (original)
+++ pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCodespaceRange.java Sun Jul 26 15:04:21 2020
@@ -46,11 +46,17 @@ public class TestCodespaceRange extends
      */
     public void testConstructor()
     {
+        // PDFBOX-4923 "1 begincodespacerange <00> <ffff> endcodespacerange" case is accepted
         byte[] startBytes1 = new byte[] { 0x00 };
-        byte[] endBytes2 = new byte[] { 0x01, 0x20 };
+        byte[] endBytes2 = new byte[] { -1, -1 };
+        new CodespaceRange(startBytes1, endBytes2);
+
+        // other cases of different lengths are not
+        byte[] startBytes3 = new byte[] { 0x01 };
+        byte[] endBytes4 = new byte[] { 0x01, 0x20 };
         try
         {
-            new CodespaceRange(startBytes1, endBytes2);
+            new CodespaceRange(startBytes3, endBytes4);
             fail("The constructor should have thrown an IllegalArgumentException exception.");
         }
         catch (IllegalArgumentException exception)