pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1649737 - /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java
Date Tue, 06 Jan 2015 06:11:28 GMT
Author: jahewson
Date: Tue Jan  6 06:11:28 2015
New Revision: 1649737

URL: http://svn.apache.org/r1649737
Log:
PDFBOX-2572: Tolerate malformed format 12 cmap subtables

Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java?rev=1649737&r1=1649736&r2=1649737&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/CmapSubtable.java Tue Jan  6
06:11:28 2015
@@ -231,30 +231,33 @@ public class CmapSubtable
             long endCode = data.readUnsignedInt();
             long startGlyph = data.readUnsignedInt();
 
-            if (firstCode < 0 || firstCode > 0x0010FFFF || (firstCode >= 0x0000D800
&& firstCode <= 0x0000DFFF))
+            if (firstCode < 0 || firstCode > 0x0010FFFF ||
+                firstCode >= 0x0000D800 && firstCode <= 0x0000DFFF)
             {
-                throw new IOException("Invalid Characters codes");
+                throw new IOException("Invalid characters codes");
             }
 
-            if ((endCode > 0 && endCode < firstCode) || endCode > 0x0010FFFF
-                    || (endCode >= 0x0000D800 && endCode <= 0x0000DFFF))
+            if (endCode > 0 && endCode < firstCode ||
+                endCode > 0x0010FFFF ||
+                endCode >= 0x0000D800 && endCode <= 0x0000DFFF)
             {
-                throw new IOException("Invalid Characters codes");
+                throw new IOException("Invalid characters codes");
             }
 
-            for (long j = 0; j <= (endCode - firstCode); ++j)
+            for (long j = 0; j <= endCode - firstCode; ++j)
             {
-
-                if ((firstCode + j) > Integer.MAX_VALUE)
+                long glyphIndex = startGlyph + j;
+                if (glyphIndex >= numGlyphs)
                 {
-                    throw new IOException("Character Code greater than Integer.MAX_VALUE");
+                    LOG.warn("Format 12 cmap contains an invalid glyph index");
+                    break;
                 }
 
-                long glyphIndex = (startGlyph + j);
-                if (glyphIndex > numGlyphs || glyphIndex > Integer.MAX_VALUE)
+                if (firstCode + j > 0x10FFFF)
                 {
-                    throw new IOException("CMap contains an invalid glyph index");
+                    LOG.warn("Format 12 cmap contains character beyond UCS-4");
                 }
+
                 glyphIdToCharacterCode[(int) glyphIndex] = (int) (firstCode + j);
                 characterCodeToGlyphId.put((int) (firstCode + j), (int) glyphIndex);
             }
@@ -279,7 +282,8 @@ public class CmapSubtable
 
             if (glyphId > numGlyphs)
             {
-                throw new IOException("CMap contains an invalid glyph index");
+                LOG.warn("Format 13 cmap contains an invalid glyph index");
+                break;
             }
 
             if (firstCode < 0 || firstCode > 0x0010FFFF || (firstCode >= 0x0000D800
&& firstCode <= 0x0000DFFF))
@@ -293,13 +297,18 @@ public class CmapSubtable
                 throw new IOException("Invalid Characters codes");
             }
 
-            for (long j = 0; j <= (endCode - firstCode); ++j)
+            for (long j = 0; j <= endCode - firstCode; ++j)
             {
-
-                if ((firstCode + j) > Integer.MAX_VALUE)
+                if (firstCode + j > Integer.MAX_VALUE)
                 {
                     throw new IOException("Character Code greater than Integer.MAX_VALUE");
                 }
+
+                if (firstCode + j > 0x10FFFF)
+                {
+                    LOG.warn("Format 13 cmap contains character beyond UCS-4");
+                }
+
                 glyphIdToCharacterCode[(int) glyphId] = (int) (firstCode + j);
                 characterCodeToGlyphId.put((int) (firstCode + j), (int) glyphId);
             }



Mime
View raw message