Skip to content

Commit

Permalink
Try to fix some issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpountz committed Feb 9, 2024
1 parent ad2c021 commit d22ef48
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
7 changes: 7 additions & 0 deletions libs/zstd/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ dependencies {
api project(':libs:elasticsearch-core')
implementation "net.java.dev.jna:jna:${versions.jna}"

// zstd native implementation bundles
runtimeOnly "org.elasticsearch:zstd:${versions.zstd}:darwin-aarch64"
runtimeOnly "org.elasticsearch:zstd:${versions.zstd}:darwin-x86-64"
runtimeOnly "org.elasticsearch:zstd:${versions.zstd}:linux-aarch64"
runtimeOnly "org.elasticsearch:zstd:${versions.zstd}:linux-x86-64"
runtimeOnly "org.elasticsearch:zstd:${versions.zstd}:windows-x86-64"

testImplementation(project(":test:framework")) {
exclude group: 'org.elasticsearch', module: 'elasticsearch-zstd'
}
Expand Down
15 changes: 9 additions & 6 deletions libs/zstd/src/main/java/org/elasticsearch/zstd/Zstd.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.sun.jna.Library;
import com.sun.jna.Native;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
Expand All @@ -22,12 +23,14 @@
public final class Zstd {

private static ZstdLibrary load() {
String zstdPath;
try {
zstdPath = Native.extractFromResourcePath("zstd").getAbsolutePath();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
File zstdFile = AccessController.doPrivileged((PrivilegedAction<File>) () -> {
try {
return Native.extractFromResourcePath("zstd");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
String zstdPath = zstdFile.getAbsolutePath();
return AccessController.doPrivileged((PrivilegedAction<ZstdLibrary>) () -> Native.load(zstdPath, ZstdLibrary.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import javax.security.auth.kerberos.ServicePermission;

public class PolicyUtil {
private static final Pattern CODEBASE_ALIAS_CLASSIFIER_PATTERN = Pattern.compile(".*-(?:\\d+(?:\\.)?)+(?:-SNAPSHOT)?(-.+)?\\.jar");
private static final Pattern CODEBASE_ALIAS_CLASSIFIER_PATTERN = Pattern.compile(".*(-(?:darwin|linux|windows)-.*)\\.jar");

// this object is checked by reference, so the value in the list does not matter
static final List<String> ALLOW_ALL_NAMES = List.of("ALLOW ALL NAMES SENTINEL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ grant codeBase "${codebase.jna}" {
// for registering native methods
permission java.lang.RuntimePermission "accessDeclaredMembers";
permission java.lang.reflect.ReflectPermission "newProxyInPackage.org.elasticsearch.zstd";
permission java.io.FilePermission "*", "read";
};

grant codeBase "${codebase.log4j-api}" {
Expand All @@ -86,6 +87,7 @@ grant codeBase "${codebase.elasticsearch-preallocate}" {

grant codeBase "${codebase.elasticsearch-zstd}" {
permission java.lang.reflect.ReflectPermission "newProxyInPackage.org.elasticsearch.zstd";
permission java.io.FilePermission "*", "read";
};

//// Everything else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ grant codeBase "${codebase.netty-transport}" {
};

grant codeBase "${codebase.jna}" {
permission java.io.FilePermission "*" "read";
permission java.io.FilePermission "*", "read";
};

grant {
Expand Down

0 comments on commit d22ef48

Please sign in to comment.