File fix-infinite-loop.patch of Package apache-pdfbox.7990

From f63db504324c74ec1d83ca8ad40886f514b8cb42 Mon Sep 17 00:00:00 2001
From: Tilman Hausherr <tilman@apache.org>
Date: Thu, 21 Jun 2018 19:45:11 +0000
Subject: [PATCH] PDFBOX-4071: clarify code + test

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/branches/1.8@1834047 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/fontbox/afm/AFMParser.java     | 12 ++++--
 .../java/org/apache/fontbox/afm/AFMParserTest.java | 43 ++++++++++++++++++++++
 2 files changed, 51 insertions(+), 4 deletions(-)
 create mode 100644 fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java

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 13365cf1d..b752d8375 100644
--- a/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java
+++ b/fontbox/src/main/java/org/apache/fontbox/afm/AFMParser.java
@@ -998,9 +998,11 @@ private String readLine() throws IOException
         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();
     }
@@ -1025,9 +1027,11 @@ private String readString() throws IOException
         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();
     }
diff --git a/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java b/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java
new file mode 100644
index 000000000..8085d8587
--- /dev/null
+++ b/fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fontbox.afm;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author Tilman Hausherr
+ */
+public class AFMParserTest
+{
+    @Test
+    public void testEof() throws IOException
+    {
+        try
+        {
+            new AFMParser(new ByteArrayInputStream("huhu".getBytes())).parse();
+        }
+        catch (IOException ex)
+        {
+            Assert.assertEquals("Error: The AFM file should start with StartFontMetrics and not 'huhu'", ex.getMessage());
+        }
+    }
+}
openSUSE Build Service is sponsored by