You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2026/03/25 15:49:34 UTC

svn commit: r1932554 - pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser

Author: msahyoun
Date: Wed Mar 25 15:49:33 2026
New Revision: 1932554

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

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

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java	Wed Mar 25 15:46:16 2026	(r1932553)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java	Wed Mar 25 15:49:33 2026	(r1932554)
@@ -51,7 +51,9 @@ public class PDFStreamParser extends Bas
 
     private final List<Object> streamObjects = new ArrayList<Object>( 100 );
     
-    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;