You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ju...@apache.org on 2010/09/03 23:35:31 UTC

svn commit: r992483 - in /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf: MemoryTTFDataStream.java TTFDataStream.java

Author: jukka
Date: Fri Sep  3 21:35:30 2010
New Revision: 992483

URL: http://svn.apache.org/viewvc?rev=992483&view=rev
Log:
PDFBOX-808: PDTrueTypeFont.loadTTF() freezes

Fix the problem caused by MemoryTTFDataStream returning 0 instead of -1 when the end of a TTF stream is reached.

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

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/MemoryTTFDataStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/MemoryTTFDataStream.java?rev=992483&r1=992482&r2=992483&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/MemoryTTFDataStream.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/MemoryTTFDataStream.java Fri Sep  3 21:35:30 2010
@@ -169,7 +169,7 @@ public class MemoryTTFDataStream extends
      * @param off The offset into the buffer.
      * @param len The length into the buffer.
      * 
-     * @return The number of bytes read.
+     * @return The number of bytes read, or -1 at the end of the stream
      * 
      * @throws IOException If there is an error reading from the stream.
      */
@@ -178,11 +178,14 @@ public class MemoryTTFDataStream extends
             int len)
      throws IOException
      {
-        int amountRead = Math.min( len, data.length-currentPosition );
-        System.arraycopy(data,currentPosition,b, off, amountRead );
-        currentPosition+=amountRead;
-        
-        return amountRead;
+        if (currentPosition < data.length) {
+            int amountRead = Math.min( len, data.length-currentPosition );
+            System.arraycopy(data,currentPosition,b, off, amountRead );
+            currentPosition+=amountRead;
+            return amountRead;
+        } else {
+            return -1;
+        }
      }
     
     /**

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java?rev=992483&r1=992482&r2=992483&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TTFDataStream.java Fri Sep  3 21:35:30 2010
@@ -194,7 +194,11 @@ public abstract class TTFDataStream 
                 && (amountRead = read( data, totalAmountRead, numberOfBytes-totalAmountRead ) ) != -1) {
             totalAmountRead += amountRead;
         }
-        return data;
+        if (totalAmountRead == numberOfBytes) {
+            return data;
+        } else {
+            throw new IOException("Unexpected end of TTF stream reached");
+        }
     }
     
     /**
@@ -204,7 +208,7 @@ public abstract class TTFDataStream 
      * @param off The offset into the buffer.
      * @param len The length into the buffer.
      * 
-     * @return The number of bytes read.
+     * @return The number of bytes read, or -1 at the end of the stream
      * 
      * @throws IOException If there is an error reading from the stream.
      */