From 96708d737a9eaa5f950ca9aead18bf93a728d754 Mon Sep 17 00:00:00 2001
Subject: [PATCH] Fix CVE-2018-8036
---
 .../main/java/org/apache/fontbox/afm/AFMParser.java  | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java b/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java
index 2ac3dbe..320df7b 100644
--- a/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java
+++ b/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java
@@ -951,9 +951,11 @@ public class AFMParser
         buf.append( (char)nextByte );
 
         //now read the data
-        while( !isEOL(nextByte = input.read()) )
+        nextByte = input.read();
+        while (nextByte != -1 && !isEOL(nextByte))
         {
-            buf.append( (char)nextByte );
+            buf.append((char)nextByte);
+            nextByte = input.read();
         }
         return buf.toString();
     }
@@ -978,9 +980,11 @@ public class AFMParser
         buf.append( (char)nextByte );
 
         //now read the data
-        while( !isWhitespace(nextByte = input.read()) )
+        nextByte = input.read();
+        while(nextByte != -1 && !isWhitespace(nextByte))
         {
-            buf.append( (char)nextByte );
+            buf.append((char)nextByte);
+            nextByte = input.read();
         }
         return buf.toString();
     }
-- 
2.23.0

