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

commit 56b5c4dcdffbde27870df5a3105d6a5f9b22f554
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Wed Mar 13 22:34:15 2024 -0400

    [CONFIGURATION-840] StackOverflowError when adding property in
    AbstractListDelimiterHandler.flattenIterator()
---
 src/changes/changes.xml                                  |  2 ++
 .../configuration2/convert/ListDelimiterHandler.java     |  6 +++++-
 .../configuration2/TestPropertiesConfiguration.java      | 16 ++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f8e5e38f..e49118ee 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,8 @@
   </properties>
   <body>
     <release version="2.10.1" date="YYYY-MM-DD" description="Minor release 
with new features and updated dependencies.">
+      <!-- FIX -->
+      <action type="fix" issue="CONFIGURATION-840" dev="ggregory" due-to="Gary 
Gregory">StackOverflowError when adding property in 
AbstractListDelimiterHandler.flattenIterator().</action>
       <!-- UPDATE -->
       <action type="update" dev="ggregory" due-to="Dependabot">Bump 
jackson-databind from 2.16.1 to 2.17.0 #297, #303, #326, #331, #340, 
#378.</action>
       <action type="update" dev="ggregory" due-to="Dependabot">Bump 
log4j.version from 2.23.0 to 2.23.1 #379.</action>
diff --git 
a/src/main/java/org/apache/commons/configuration2/convert/ListDelimiterHandler.java
 
b/src/main/java/org/apache/commons/configuration2/convert/ListDelimiterHandler.java
index 9ddd57e8..d0fc1ef0 100644
--- 
a/src/main/java/org/apache/commons/configuration2/convert/ListDelimiterHandler.java
+++ 
b/src/main/java/org/apache/commons/configuration2/convert/ListDelimiterHandler.java
@@ -17,6 +17,7 @@
 package org.apache.commons.configuration2.convert;
 
 import java.lang.reflect.Array;
+import java.nio.file.Path;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -121,7 +122,10 @@ public interface ListDelimiterHandler {
             return split((String) value, true);
         }
         final Collection<Object> result = new LinkedList<>();
-        if (value instanceof Iterable) {
+        if (value instanceof Path) {
+            // Don't handle as an Iterable.
+            result.add(value);
+        } else if (value instanceof Iterable) {
             AbstractListDelimiterHandler.flattenIterator(this, result, 
((Iterable<?>) value).iterator(), limit);
         } else if (value instanceof Iterator) {
             AbstractListDelimiterHandler.flattenIterator(this, result, 
(Iterator<?>) value, limit);
diff --git 
a/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
 
b/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
index 0c80fd2d..52fd5bc0 100644
--- 
a/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
+++ 
b/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
@@ -51,7 +51,9 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.FileSystems;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
@@ -433,6 +435,20 @@ public class TestPropertiesConfiguration {
         assertFalse(conf.containsKey("!comment"));
     }
 
+    @Test
+    public void testCompress840() {
+        final PropertiesConfiguration configuration = new 
PropertiesConfiguration();
+        final Path path = FileSystems.getDefault().getPath("bar");
+        final ListDelimiterHandler listDelimiterHandler = 
configuration.getListDelimiterHandler();
+        listDelimiterHandler.flatten(path, 0);
+        // Stack overflow:
+        listDelimiterHandler.flatten(path, 1);
+        listDelimiterHandler.flatten(path, Integer.MAX_VALUE);
+        listDelimiterHandler.parse(path);
+        configuration.addProperty("foo", path);
+        configuration.toString();
+    }
+
     /**
      * Tests copying another configuration into the test configuration. This 
test ensures that the layout object is informed
      * about the newly added properties.

Reply via email to