Repository navigation
[pull] master from microsoft:master - #150
Merged
Merged
Conversation
libgit2 treats every string it receives and returns as UTF-8. The LibGit2Repo P/Invoke declarations left CharSet unset, so a bare [DllImport] string parameter defaulted to CharSet.Ansi and encoded through the Windows ANSI code page. On a non-UTF-8 code page an unmappable character (for example a repository path under a non-English Windows user name, such as "C:\Users\...\café_日本語") was dropped to '?', so git_repository_open resolved the wrong path and the constructor threw InvalidDataException. Annotate every string parameter with [MarshalAs(UnmanagedType.LPUTF8Str)]. This covers the repository path (git_repository_open), the revspec (git_revparse_single), the object id string (git_oid_fromstr), and the config keys (git_config_get_string, git_config_get_bool, git_config_get_multivar_foreach). Read the borrowed git_error.message pointer as an IntPtr and copy it with Marshal.PtrToStringUTF8, matching the existing GitConfigEntry pattern, so the interop marshaller never frees libgit2's heap memory. The config value output path already used Marshal.PtrToStringUTF8, so it is unchanged. Add LibGit2NonAsciiPathTests, which opens a real repository at a non-ASCII path through git2.dll and reads a non-ASCII config value. Before the fix both cases fail with "No mapping for the Unicode character exists in the target multi-byte code page"; after the fix they pass. The fixture ignores itself when the active ANSI code page is already UTF-8 (CP65001), where the bug cannot reproduce. Document the UTF-8 marshalling contract on the LibGit2Repo class and in AGENTS.md so future libgit2 bindings do not regress. Assisted-by: Claude Opus 4.8 Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
Marshal libgit2 P/Invoke strings as UTF-8, not ANSI
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )