Skip to content

Commit 970e353

Browse files
author
Maruan Sahyoun
committed
PDFBOX-5660: optimize/remove regex, 2nd attempt for Sonar
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1932548 13f79535-47bb-0310-9956-ffa450edef68
1 parent bc116a4 commit 970e353

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public class PDFStreamParser extends COSParser
4747
*/
4848
private static final Logger LOG = LogManager.getLogger(PDFStreamParser.class);
4949

50-
private static final Pattern NUMBER_PATTERN = Pattern.compile("^(?>\\d*)\\.?(?>\\d*)$");
50+
// Pattern to match numbers (integers or decimals). Safe from ReDoS: no overlapping quantifiers
51+
// or character classes that cause backtracking. The optional decimal group is explicit and bounded.
52+
private static final Pattern NUMBER_PATTERN = Pattern.compile("^\\d*(\\.\\d*)?$");
5153
private static final int MAX_BIN_CHAR_TEST_LENGTH = 10;
5254
private final byte[] binCharTestArr = new byte[MAX_BIN_CHAR_TEST_LENGTH];
5355
private int inlineImageDepth = 0;

0 commit comments

Comments
 (0)