Windows: JNA fails to load libraries if SetDefaultDllDirectories() was used
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- java
調査の方向性
まず、JNA のネイティブライブラリ読み込みパスを Native.load から LoadLibraryExW の呼び出しまで追跡し、次に SetDefaultDllDirectories() を使用した後で、提供された例を再現します。相対ライブラリ名の動作を Windows の文書化された検索パス規則と比較します。例が正常に読み込まれ、回帰がテストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
- Version of JNA and related jars - any since 93ebb9f7
- Version and vendor of the java virtual machine - any
- Operating system - any Windows
- System architecture (CPU type, bitness of the JVM) - any
Example snippet:
public interface Dwmapi extends StdCallLibrary {
}
public interface Kernel32_2 extends StdCallLibrary {
Pointer AddDllDirectory(WString NewDirectory);
boolean SetDefaultDllDirectories(int DirectoryFlags);
}
public static void main(String[] args) {
final Kernel32_2 kernel32 = Native.loadLibrary("kernel32", Kernel32_2.class);
final int LOAD_LIBRARY_DEFAULT_DIRS = 0x00001000;
// SetDefaultDllDirectories() is used to supply another DLL search path.
// But it causes JNA to fail later.
Path pluginsPath = Paths.get("plugins").toAbsolutePath();
kernel32.SetDefaultDllDirectories(LOAD_LIBRARY_DEFAULT_DIRS);
kernel32.AddDllDirectory(new WString(pluginsPath.toString()));
// This is perfectly fine, but fails after SetDefaultDllDirectories().
Native.load("dwmapi", Dwmapi.class);
}
Explanation:
- Since 93ebb9f7, JNA uses
LOAD_WITH_ALTERED_SEARCH_PATHinLoadLibraryExW(). - MSDN says:
If this value is used and lpFileName specifies a relative path, the behavior is undefined - When library name is given like
"dwmapi", this is a relative path. - Windows logs this error, but still tries to proceed - set WinDBG breakpoint to see for yourself:
bp ntdll!LdrpLogRelativePathWithAlteredSearchError "du @rcx"(here, even the function's name is already a proof) - However, if
SetDefaultDllDirectories()was also used,ntdll!LdrpGetDllPathconsiders this a fatal error and returnsSTATUS_INVALID_PARAMETER
TLDR: JNA uses LOAD_WITH_ALTERED_SEARCH_PATH and this is a bug to use it with non-absolute path. However, in most cases it still works, because Windows is kind to interlopers.
- 主要言語
- Java
- スター
- 8.9k
- フォーク
- 1.7k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
java-native-access/jna のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
java-native-access/jna#1740 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 66/100
java-native-access/jna#1738 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
java-native-access/jna#1736 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
java-native-access/jna#1717 ·
-
Windows32Exception - The parameter is incorrect再び着手できるかも @marktech0813 が 330 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
java-native-access/jna#1700 · コメント 11 件 ·
java-native-access/jna の issue をすべて見る
似ている issue
-
Mend: dependency security vulnerability
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
opfab/operatorfabric-core#10653 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
GeminiUtil placeholder user turn ("Continue output. DO NOT look at this line ...") is flagged by prompt injection filters対応中かも @innoprej が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
salesforce/multicloudj#667 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 2 日以内に返信