Skip to content

[pull] master from microsoft:master - #150

Merged
pull[bot] merged 2 commits into
cgallred:masterfrom
microsoft:master
Sep 23, 2026
Merged

pull[bot] merged 2 commits into
cgallred:masterfrom
microsoft:master

Conversation

@pull

@pull pull Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

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 : )

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
@pull pull Bot locked and limited conversation to collaborators Sep 23, 2026
@pull pull Bot added the ⤵️ pull label Sep 23, 2026
@pull
pull Bot merged commit f4728ba into cgallred:master Sep 23, 2026
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant