pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1868399 - in /pdfbox/branches/2.0/fontbox/src: main/java/org/apache/fontbox/cmap/CMapParser.java test/java/org/apache/fontbox/cmap/TestCMapParser.java test/resources/cmap/CMapMalformedbfrange2
Date Sun, 13 Oct 2019 12:01:53 GMT
Author: lehmi
Date: Sun Oct 13 12:01:53 2019
New Revision: 1868399

URL: http://svn.apache.org/viewvc?rev=1868399&view=rev
Log:
PDFBOX-4661: avoid overflow of the last byte following the spec, as proposed by Michael Klink

Modified:
    pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java
    pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java
    pdfbox/branches/2.0/fontbox/src/test/resources/cmap/CMapMalformedbfrange2

Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java?rev=1868399&r1=1868398&r2=1868399&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/cmap/CMapParser.java Sun
Oct 13 12:01:53 2019
@@ -383,18 +383,14 @@ public class CMapParser
             // PDFBOX-3807: ignore null
             else if (nextToken instanceof byte[])
             {
-                // the range can not represent more that 255 values
-                // PDFBOX-4661: be more lenient and support 256 values as well
-                if ((end - start) > 256)
-                {
-                    // PDFBOX-4550: likely corrupt stream
-                    break;
-                }
                 byte[] tokenBytes = (byte[]) nextToken;
                 // PDFBOX-3450: ignore <>
                 if (tokenBytes.length > 0)
                 {
-                    addMappingFrombfrange(result, startCode, end - start + 1, tokenBytes);
+                    // PDFBOX-4661: avoid overflow of the last byte, all following values
are undefined
+                    int values = Math.min(end - start + 1,
+                            255 - (tokenBytes[tokenBytes.length - 1] & 0xFF));
+                    addMappingFrombfrange(result, startCode, values, tokenBytes);
                 }
             }
         }

Modified: pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java?rev=1868399&r1=1868398&r2=1868399&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java
(original)
+++ pdfbox/branches/2.0/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java
Sun Oct 13 12:01:53 2019
@@ -146,12 +146,13 @@ public class TestCMapParser extends Test
 
         assertNotNull("Failed to parse malformed CMap file", cMap);
 
-        byte[] bytes1 = { 0, 1 };
-        assertEquals("bytes 00 01 from bfrange <0001> <0009> <0041>", "A",
-                cMap.toUnicode(toInt(bytes1, bytes1.length)));
+        assertEquals("bytes 00 01 from bfrange <0001> <0009> <0030>", "0",
cMap.toUnicode(0x001));
 
-        byte[] bytes2 = { 2, 00 };
-        assertNull(cMap.toUnicode(toInt(bytes2, bytes2.length)));
+        assertEquals("bytes 02 32 from bfrange <0232> <0432> <0041>", "A",
cMap.toUnicode(0x232));
+
+        // check border values
+        assertNotNull(cMap.toUnicode(0x2EF));
+        assertNull(cMap.toUnicode(0x2F0));
 
     }
 

Modified: pdfbox/branches/2.0/fontbox/src/test/resources/cmap/CMapMalformedbfrange2
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/test/resources/cmap/CMapMalformedbfrange2?rev=1868399&r1=1868398&r2=1868399&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/test/resources/cmap/CMapMalformedbfrange2 (original)
+++ pdfbox/branches/2.0/fontbox/src/test/resources/cmap/CMapMalformedbfrange2 Sun Oct 13 12:01:53
2019
@@ -18,12 +18,12 @@
 %%
 %%EndComments
 
-1 begincodespacerange<0000> <02FF>
+1 begincodespacerange<0000> <04FF>
 endcodespacerange
 
 2 beginbfrange
-<0001> <0009> <0041>
-<0200> <0400> <0030>
+<0001> <0009> <0030>
+<0232> <0432> <0041>
 endbfrange
 
 endcmap



Mime
View raw message