Skip to content

Commit 0f26f42

Browse files
committed
Defensively check for jar separator in jar entry names
Closes gh-34126
1 parent c48fec8 commit 0f26f42

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.Collections;
4141
import java.util.Enumeration;
4242
import java.util.HashSet;
43+
import java.util.Iterator;
4344
import java.util.LinkedHashSet;
4445
import java.util.Map;
4546
import java.util.NavigableSet;
@@ -806,7 +807,7 @@ protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource,
806807
if (separatorIndex == -1) {
807808
separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
808809
}
809-
if (separatorIndex != -1) {
810+
if (separatorIndex >= 0) {
810811
jarFileUrl = urlFile.substring(0, separatorIndex);
811812
rootEntryPath = urlFile.substring(separatorIndex + 2); // both separators are 2 chars
812813
NavigableSet<String> entriesCache = this.jarEntriesCache.get(jarFileUrl);
@@ -874,7 +875,13 @@ protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource,
874875
}
875876
Set<Resource> result = new LinkedHashSet<>(64);
876877
NavigableSet<String> entriesCache = new TreeSet<>();
877-
for (String entryPath : jarFile.stream().map(JarEntry::getName).sorted().toList()) {
878+
Iterator<String> entryIterator = jarFile.stream().map(JarEntry::getName).sorted().iterator();
879+
while (entryIterator.hasNext()) {
880+
String entryPath = entryIterator.next();
881+
int entrySeparatorIndex = entryPath.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
882+
if (entrySeparatorIndex >= 0) {
883+
entryPath = entryPath.substring(entrySeparatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length());
884+
}
878885
entriesCache.add(entryPath);
879886
if (entryPath.startsWith(rootEntryPath)) {
880887
String relativePath = entryPath.substring(rootEntryPath.length());

0 commit comments

Comments
 (0)