You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/03/02 02:33:54 UTC

(commons-configuration) branch master updated: CONFIGURATION-838: Fix stack overflow when parsing (#369)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-configuration.git


The following commit(s) were added to refs/heads/master by this push:
     new 6cfee556 CONFIGURATION-838: Fix stack overflow when parsing (#369)
6cfee556 is described below

commit 6cfee55638858187eabb1258b41ddaa86c5ba22b
Author: Ian Lynagh <ig...@github.com>
AuthorDate: Sat Mar 2 02:33:48 2024 +0000

    CONFIGURATION-838: Fix stack overflow when parsing (#369)
    
    * CONFIGURATION-838: Add a test for the property reader that stack overflows
    
    * CONFIGURATION-838: Fix stack overflow in property reader with extreme inputs
---
 .../commons/configuration2/PropertiesConfiguration.java       |  2 +-
 .../commons/configuration2/TestPropertiesConfiguration.java   | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java b/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
index b49f4531..c3e89663 100644
--- a/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
+++ b/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
@@ -458,7 +458,7 @@ public class PropertiesConfiguration extends BaseConfiguration implements FileBa
 
         /** The regular expression to parse the key and the value of a property. */
         private static final Pattern PROPERTY_PATTERN = Pattern
-            .compile("(([\\S&&[^\\\\" + new String(SEPARATORS) + "]]|\\\\.)*)(\\s*(\\s+|[" + new String(SEPARATORS) + "])\\s*)?(.*)");
+            .compile("(([\\S&&[^\\\\" + new String(SEPARATORS) + "]]|\\\\.)*+)(\\s*(\\s+|[" + new String(SEPARATORS) + "])\\s*)?(.*)");
 
         /** Constant for the index of the group for the key. */
         private static final int IDX_KEY = 1;
diff --git a/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java b/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
index af6bd76f..2f3db502 100644
--- a/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
+++ b/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
@@ -56,6 +56,7 @@ import java.nio.file.Paths;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -490,6 +491,16 @@ public class TestPropertiesConfiguration {
         assertEquals("bar", conf.getString("foo"));
     }
 
+    @Test
+    public void testLargeKey() throws Exception {
+        conf.clear();
+        String key = String.join("", Collections.nCopies(10000, "x"));
+        final FileHandler handler = new FileHandler(conf);
+        handler.load(new StringReader(key));
+
+        assertEquals("", conf.getString(key));
+    }
+
     /**
      * Check that key/value separators can be part of a key.
      */