Skip to content

Commit

Permalink
Reject invalid service files (#62)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
FiniteReality authored Mar 27, 2024
1 parent 38b063e commit f4a3e66
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/cpw/mods/jarhandling/impl/JarContentsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class JarContentsImpl implements JarContents {
.filter(fsp->fsp.getScheme().equals("union"))
.findFirst()
.orElseThrow(()->new IllegalStateException("Couldn't find UnionFileSystemProvider"));
private static final Set<String> NAUGHTY_SERVICE_FILES = Set.of("org.codehaus.groovy.runtime.ExtensionModule");

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

0 comments on commit f4a3e66

Please sign in to comment.