Skip to content

invalid config path selector 1874839136 #6255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
frindler opened this issue Mar 29, 2022 · 4 comments
Closed

invalid config path selector 1874839136 #6255

frindler opened this issue Mar 29, 2022 · 4 comments

Comments

@frindler
Copy link

This is a duplicate of libgit2/libgit2sharp#1951 (for libgit2sharp), but I think it is probably an issue with libgit2 more than with libgit2sharp (at least it's unclear to me what to do about it on the managed end).

When trying to run the libgit2sharp tests (freshly cloned repo) on my Apple Silicon Mac (arm64), using the arm64 version of the .NET 6 SDK, all tests fail with an exception. If I use the x64 SDK, it runs just fine.

Reproduction steps

Just clone the libgit2sharp repo, add binaries NuGet package libgit2sharp.nativebinaries try to run tests.

Expected behavior

Tests should pass.

Actual behavior

LibGit2Sharp.LibGit2SharpException
invalid config path selector 1874839136
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in /Playground/libgit2sharp/LibGit2Sharp/Core/Ensure.cs:line 154
at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) in /Playground/libgit2sharp/LibGit2Sharp/Core/Ensure.cs:line 172
at LibGit2Sharp.Core.Proxy.git_libgit2_opts_set_search_path(ConfigurationLevel level, String path) in /Playground/libgit2sharp/LibGit2Sharp/Core/Proxy.cs:line 3436
at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths(ConfigurationLevel level, String[] paths) in /Playground/libgit2sharp/LibGit2Sharp/GlobalSettings.cs:line 337
at LibGit2Sharp.Tests.TestHelpers.BaseFixture.BuildFakeConfigs(IPostTestDirectoryRemover dirRemover) in /Playground/libgit2sharp/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs:line 125
at LibGit2Sharp.Tests.TestHelpers.BaseFixture..ctor() in /Playground/libgit2sharp/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs:line 20
at LibGit2Sharp.Tests.ArchiveTarFixture..ctor()
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

This is here:

public static void git_libgit2_opts_set_search_path(ConfigurationLevel level, string path)
        {
            var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetSearchPath, (uint)level, path);
            Ensure.ZeroResult(res);
        }

level is 4, but seems to get marshalled wrong to libgit2 (where it seems to arrive as 1874839136).

In libgit2 this seems to arrive at the following function in libgit2.c:

int git_libgit2_opts(int key, ...)
{
	int error = 0;
	va_list ap;

	va_start(ap, key);

	switch (key) {
	
{{omitted irrelevant cases}}

	case GIT_OPT_GET_SEARCH_PATH:
		{
			int sysdir = va_arg(ap, int);
			git_buf *out = va_arg(ap, git_buf *);
			git_str str = GIT_STR_INIT;
			const git_str *tmp;
			int level;

			if ((error = git_buf_tostr(&str, out)) < 0 ||
			    (error = config_level_to_sysdir(&level, sysdir)) < 0 ||
			    (error = git_sysdir_get(&tmp, level)) < 0 ||
			    (error = git_str_put(&str, tmp->ptr, tmp->size)) < 0)
				break;

			error = git_buf_fromstr(out, &str);
		}
		break;

	case GIT_OPT_SET_SEARCH_PATH:
		{
			int level;

			if ((error = config_level_to_sysdir(&level, va_arg(ap, int))) >= 0)
				error = git_sysdir_set(level, va_arg(ap, const char *));
		}
		break;

{{etc.}}

then it goes to

static int config_level_to_sysdir(int *out, int config_level)
{
	switch (config_level) {
	case GIT_CONFIG_LEVEL_SYSTEM:
		*out = GIT_SYSDIR_SYSTEM;
		return 0;
	case GIT_CONFIG_LEVEL_XDG:
		*out = GIT_SYSDIR_XDG;
		return 0;
	case GIT_CONFIG_LEVEL_GLOBAL:
		*out = GIT_SYSDIR_GLOBAL;
		return 0;
	case GIT_CONFIG_LEVEL_PROGRAMDATA:
		*out = GIT_SYSDIR_PROGRAMDATA;
		return 0;
	default:
		break;
	}

	git_error_set(
		GIT_ERROR_INVALID, "invalid config path selector %d", config_level);
	return -1;
}

and this seems to produce this error.

Version of libgit2 and LibGit2Sharp (release number or SHA1)

Libgit2Sharp: 1e6da83ab8c47058b5b4ef1e4e28e4732de44db0
Libgit2: b7bad55 (that's what's included in the libgit2 binaries package)

Operating system(s) tested; .NET runtime tested

MacOS Monterey 12.3, Apple Silicon, .NET 6 Arm64 SDK

@frindler
Copy link
Author

@ethomson
Copy link
Member

Looks like LibGit2Sharp is erroneously casting an int as a uint?

@frindler
Copy link
Author

Thanks for the quick reply! I just tried to change the uint to int, but the result is the same exception.
However: The number I'm getting is different every time I run the tests (didn't realize this at first since for some reason they all start with 18...). So this looks like some uninitialized memory is being interpreted as an int. Could there be an issue with the calling convention on arm64 (maybe some wrong alignment/padding)? Sorry, this is far from my own expertise...
Let me also say that I'm quite happy to make the necessary changes to libgit2sharp and submit a pull request if we can figure out what's wrong here.

@frindler
Copy link
Author

frindler commented Apr 1, 2022

This is now fixed in libgit2/libgit2sharp#1955

The problem are the variadic arguments passed to git_libgit2_opts. On arm64 they need to be padded to start from the 9th argument. The solution is not particularly pretty, but this seems to be the best option at the moment).

See also for more on this issue:
dotnet/runtime#48752
dotnet/runtime#48796

@frindler frindler closed this as completed Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants