Skip to content

Commit 6b47266

Browse files
Merge pull request quarkusio#47667 from LucienBrule/bugfix/static-resources-oob-guard
Fix OOB in StaticResourcesProcessor for META-INF/resources-only JARs
2 parents 08252b6 + a7849ec commit 6b47266

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/StaticResourcesProcessor.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static io.quarkus.deployment.annotations.ExecutionTime.RUNTIME_INIT;
44

55
import java.nio.file.Files;
6+
import java.nio.file.Path;
67
import java.util.ArrayList;
78
import java.util.HashSet;
89
import java.util.List;
@@ -107,11 +108,17 @@ public void nativeImageResource(Optional<StaticResourcesBuildItem> staticResourc
107108
*/
108109
private Set<StaticResourcesBuildItem.Entry> getClasspathResources() {
109110
Set<StaticResourcesBuildItem.Entry> knownPaths = new HashSet<>();
111+
final String prefix = StaticResourcesRecorder.META_INF_RESOURCES;
110112
visitRuntimeMetaInfResources(visit -> {
111-
if (!Files.isDirectory(visit.getPath())) {
112-
knownPaths.add(new StaticResourcesBuildItem.Entry(
113-
visit.getRelativePath().substring(StaticResourcesRecorder.META_INF_RESOURCES.length()),
114-
false));
113+
Path visitPath = visit.getPath();
114+
if (!Files.isDirectory(visitPath)) {
115+
String rel = visit.getRelativePath();
116+
// Ensure that the relative path starts with the prefix before calling substring
117+
if (rel.startsWith(prefix)) {
118+
// Strip the "META-INF/resources/" prefix and add the remainder
119+
String subPath = rel.substring(prefix.length());
120+
knownPaths.add(new StaticResourcesBuildItem.Entry(subPath, false));
121+
}
115122
}
116123
});
117124
return knownPaths;

0 commit comments

Comments
 (0)