Skip to content

Commit

Permalink
[CONFIGURATION-840] StackOverflowError when adding property in
Browse files Browse the repository at this point in the history
AbstractListDelimiterHandler.flattenIterator()
  • Loading branch information
garydgregory committed Mar 14, 2024
1 parent ea0f24c commit 56b5c4d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,7 +122,10 @@ default Collection<?> flatten(final Object value, final int limit) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
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;
Expand Down Expand Up @@ -433,6 +435,20 @@ public void testComment() {
assertFalse(conf.containsKey("!comment"));
}

@Test

This comment has been minimized.

Copy link
@iWCs2024

iWCs2024 Jun 2, 2024

tuned

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.
Expand Down

0 comments on commit 56b5c4d

Please sign in to comment.