Skip to content

Commit f4a3e66

Browse files
Reject invalid service files (#62)
Currently, SJH throws when building a module descriptor for jars which contain files in META-INF/services which aren't valid. All this PR does is filter out these invalid files: - I've added a set of known "naughty" service files which don't follow the format correctly - It was mentioned in Discord that certain Groovy libraries define extensions with these invalid service files so I wanted to include these too - JLine 3.22.0 and above define a nested file in `META-INF/services/org/jline/terminal/provider/` which doesn't follow the service file format (it's in fact a properties file). This causes SJH to throw because `exec` is not within a named package, and is blocking upgrading to newer versions of JLine
1 parent 38b063e commit f4a3e66

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/cpw/mods/jarhandling/impl/JarContentsImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class JarContentsImpl implements JarContents {
3434
.filter(fsp->fsp.getScheme().equals("union"))
3535
.findFirst()
3636
.orElseThrow(()->new IllegalStateException("Couldn't find UnionFileSystemProvider"));
37+
private static final Set<String> NAUGHTY_SERVICE_FILES = Set.of("org.codehaus.groovy.runtime.ExtensionModule");
3738

3839
final UnionFileSystem filesystem;
3940
// Code signing data
@@ -202,8 +203,9 @@ public List<SecureJar.Provider> getMetaInfServices() {
202203
if (this.providers == null) {
203204
final var services = this.filesystem.getRoot().resolve("META-INF/services/");
204205
if (Files.exists(services)) {
205-
try (var walk = Files.walk(services)) {
206+
try (var walk = Files.walk(services, 1)) {
206207
this.providers = walk.filter(path->!Files.isDirectory(path))
208+
.filter(path -> !NAUGHTY_SERVICE_FILES.contains(path.getFileName().toString()))
207209
.map((Path path1) -> SecureJar.Provider.fromPath(path1, filesystem.getFilesystemFilter()))
208210
.toList();
209211
} catch (IOException e) {

0 commit comments

Comments
 (0)