Author: msahyoun
Date: Wed Mar 25 15:46:16 2026
New Revision: 1932553

Log:
PDFBOX-5660: optimize/remove regex, 2nd attempt for Sonar

Modified:
   
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java

Modified: 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
==============================================================================
--- 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
   Wed Mar 25 15:45:57 2026        (r1932552)
+++ 
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
   Wed Mar 25 15:46:16 2026        (r1932553)
@@ -47,7 +47,9 @@ public class PDFStreamParser extends Bas
      */
     private static final Log LOG = LogFactory.getLog(PDFStreamParser.class);
 
-    private static final Pattern NUMBER_PATTERN = 
Pattern.compile("^(?>\\d*)\\.?(?>\\d*)$");
+    // Pattern to match numbers (integers or decimals). Safe from ReDoS: no 
overlapping quantifiers
+    // or character classes that cause backtracking. The optional decimal 
group is explicit and bounded.
+    private static final Pattern NUMBER_PATTERN = 
Pattern.compile("^\\d*(\\.\\d*)?$");
     private static final int MAX_BIN_CHAR_TEST_LENGTH = 10;
     private final byte[] binCharTestArr = new byte[MAX_BIN_CHAR_TEST_LENGTH];
     private int inlineImageDepth = 0;

Reply via email to