fix: restore Windows Unicode CLI path arguments for jar and native - #1067
Open
kireetivar wants to merge 4 commits into
Open
fix: restore Windows Unicode CLI path arguments for jar and native#1067kireetivar wants to merge 4 commits into
kireetivar wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows, non-ANSI characters in host path options (for example
--from-cache,-f/--file,--source-dir) can be corrupted beforemainsees them. Any code points outside the active ANSI code page (sun.jnu.encoding, often Cp1252) can become?(JVM) or U+FFFD (some Graal native builds).This change restores those arguments at process entry for both:
java -jar fcli.jarfcli.exeby re-reading the process command line with the wide Win32 APIs
GetCommandLineW+CommandLineToArgvW(same pattern used by native CLIs and libraries such as boost.nowide / Python on Windows), then replacing only tokens that look like a lossy form of the wide originals.References (upstream / platform)
OpenJDK /
java.exelauncherjava.exeobtains UTF-16 viaGetCommandLineWbut re-encodes through theANSI code page, turning unmappable characters into
?(or??forsupplementary characters). Status: Won't Fix.
Related discussion of Windows command-line encoding and the need for wide APIs.
Related property:
sun.jnu.encoding(encoding used when parsing values from the command line on the JDK).GraalVM native-image
Native images on Windows have been observed to replace non-ASCII argv
characters with U+FFFD. Open issue; not fixed in the platform.
Because neither the JDK launcher nor (historically) Graal native-image guarantees intact Unicode argv on Windows, fcli recovers args in-process when needed.
Approach
FortifyCLI.maincallsWindowsCommandLineArgs.fixIfNeeded(args)GetCommandLineW/CommandLineToArgvW; merge only corrupted tokenssun.jnu.encodingis UTF-8; never throws?via jnu round-trip) and native-style (U+FFFD) corruptionnet.java.dev.jna:jna(core only)--initialize-at-run-time=com.sun.jna