You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2023/05/01 07:46:47 UTC

svn commit: r1909531 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java

Author: lehmi
Date: Mon May  1 07:46:47 2023
New Revision: 1909531

URL: http://svn.apache.org/viewvc?rev=1909531&view=rev
Log:
PDFBOX-4892, simplify, avoid unneeded read/rewind operation

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java?rev=1909531&r1=1909530&r2=1909531&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java Mon May  1 07:46:47 2023
@@ -369,8 +369,6 @@ public abstract class BaseParser
      *
      * The second bug was in this format /Title (c:\) /Producer
      *
-     * This patch moves this code out of the parseCOSString method, so it can be used twice.
-     *
      * @param bracesParameter the number of braces currently open.
      *
      * @return the corrected value of the brace counter
@@ -378,11 +376,13 @@ public abstract class BaseParser
      */
     private int checkForEndOfString(final int bracesParameter) throws IOException
     {
-        int braces = bracesParameter;
+        if (bracesParameter == 0)
+        {
+            return 0;
+        }
+        // Check the next 3 bytes if available
         byte[] nextThreeBytes = new byte[3];
         int amountRead = seqSource.read(nextThreeBytes);
-
-        // Check the next 3 bytes if available
         // The following cases are valid indicators for the end of the string
         // 1. Next line contains another COSObject: CR + LF + '/'
         // 2. COSDictionary ends in the next line: CR + LF + '>'
@@ -390,23 +390,24 @@ public abstract class BaseParser
         // 4. COSDictionary ends in the next line: LF + '>'
         // 5. Next line contains another COSObject: CR + '/'
         // 6. COSDictionary ends in the next line: CR + '>'
-        if (amountRead == 3)
-        {
-            if (((nextThreeBytes[0] == ASCII_CR || nextThreeBytes[0] == ASCII_LF)
-                    && (nextThreeBytes[1] == '/' || nextThreeBytes[1] == '>')) //
-                    || //
-                    (nextThreeBytes[0] == ASCII_CR && nextThreeBytes[1] == ASCII_LF
-                            && (nextThreeBytes[2] == '/' || nextThreeBytes[2] == '>')) //
-            )
-            {
-                braces = 0;
-            }
-        }
         if (amountRead > 0)
         {
             seqSource.unread(nextThreeBytes, 0, amountRead);
         }
-        return braces;
+        if (amountRead < 3)
+        {
+            return bracesParameter;
+        }
+        if (((nextThreeBytes[0] == ASCII_CR || nextThreeBytes[0] == ASCII_LF)
+                && (nextThreeBytes[1] == '/' || nextThreeBytes[1] == '>')) //
+                || //
+                (nextThreeBytes[0] == ASCII_CR && nextThreeBytes[1] == ASCII_LF
+                        && (nextThreeBytes[2] == '/' || nextThreeBytes[2] == '>')) //
+        )
+        {
+            return 0;
+        }
+        return bracesParameter;
     }
 
     /**