{"action":"created","issue":{"url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/1217","labels_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/1217/labels{/name}","comments_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/1217/comments","events_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/1217/events","html_url":"https://github.com/libgit2/libgit2sharp/issues/1217","id":113406630,"number":1217,"title":"AccessViolationException in Proxy.git_remote_push","user":{"login":"golsby","id":521547,"avatar_url":"https://avatars.githubusercontent.com/u/521547?v=3","gravatar_id":"","url":"https://api.github.com/users/golsby","html_url":"https://github.com/golsby","followers_url":"https://api.github.com/users/golsby/followers","following_url":"https://api.github.com/users/golsby/following{/other_user}","gists_url":"https://api.github.com/users/golsby/gists{/gist_id}","starred_url":"https://api.github.com/users/golsby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/golsby/subscriptions","organizations_url":"https://api.github.com/users/golsby/orgs","repos_url":"https://api.github.com/users/golsby/repos","events_url":"https://api.github.com/users/golsby/events{/privacy}","received_events_url":"https://api.github.com/users/golsby/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/libgit2/libgit2sharp/labels/Bug","name":"Bug","color":"e10c02"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/libgit2/libgit2sharp/milestones/25","html_url":"https://github.com/libgit2/libgit2sharp/milestones/v0.22","labels_url":"https://api.github.com/repos/libgit2/libgit2sharp/milestones/25/labels","id":960191,"number":25,"title":"v0.22","description":"","creator":{"login":"nulltoken","id":92363,"avatar_url":"https://avatars.githubusercontent.com/u/92363?v=3","gravatar_id":"","url":"https://api.github.com/users/nulltoken","html_url":"https://github.com/nulltoken","followers_url":"https://api.github.com/users/nulltoken/followers","following_url":"https://api.github.com/users/nulltoken/following{/other_user}","gists_url":"https://api.github.com/users/nulltoken/gists{/gist_id}","starred_url":"https://api.github.com/users/nulltoken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nulltoken/subscriptions","organizations_url":"https://api.github.com/users/nulltoken/orgs","repos_url":"https://api.github.com/users/nulltoken/repos","events_url":"https://api.github.com/users/nulltoken/events{/privacy}","received_events_url":"https://api.github.com/users/nulltoken/received_events","type":"User","site_admin":false},"open_issues":8,"closed_issues":157,"state":"open","created_at":"2015-02-01T13:52:12Z","updated_at":"2015-11-12T21:19:18Z","due_on":null,"closed_at":null},"comments":8,"created_at":"2015-10-26T17:23:00Z","updated_at":"2015-11-12T22:22:00Z","closed_at":"2015-11-12T21:17:54Z","body":"**Summary**\r\n`GitPushOptions` (CS) signature mismatch with `git_push_options` (C) causes uninitialized memory and access violation when calling `git_remote_push` in libgit2 when credentials are passed for accessing a private repo. The `custom_headers` member of `git_push_options` points to random garbage after the call is marshalled because the corresponding member is missing from `GitPushOptions`.\r\n\r\nAs a side note, GitHub Desktop cannot push to our private repo, but it doesn't report anything useful when it fails. I imagine this is the cause.\r\n\r\n**To Reproduce:**\r\nUsing commit 9d17afec6a6dd74d7afac10ddee7203727cdbcdd (Oct 23) I'm trying to push using the following code. I'm pushing to a private repo on GitHub using `username/personal access token` pair.\r\n\r\n```\r\n      if (string.IsNullOrWhiteSpace(Branch))\r\n        Branch = \"master\";\r\n\r\n      using (var repo = new Repository(WorkingTree))\r\n      {\r\n        Log.LogMessage(\"Pushing branch '{0}' from '{1}'\", Branch, WorkingTree);\r\n        LibGit2Sharp.PushOptions options = new LibGit2Sharp.PushOptions();\r\n        options.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = Username, Password = Password };\r\n        var branch = repo.Branches[Branch];\r\n        lock (m_lock)\r\n        {\r\n          repo.Network.Push(branch, options);\r\n        }\r\n      }\r\n      return true;\r\n```\r\n\r\nThis results in a 'System.AccessViolationException'.\r\n\r\n**Details**\r\nDebugging into this, I see that `git_remote_push` on line 2450 of remote.c takes `git_push_options` as a parameter. From remote.h:\r\n```\r\n/**\r\n * Controls the behavior of a git_push object.\r\n */\r\ntypedef struct {\r\n\tunsigned int version;\r\n\r\n\t/**\r\n\t * If the transport being used to push to the remote requires the creation\r\n\t * of a pack file, this controls the number of worker threads used by\r\n\t * the packbuilder when creating that pack file to be sent to the remote.\r\n\t *\r\n\t * If set to 0, the packbuilder will auto-detect the number of threads\r\n\t * to create. The default value is 1.\r\n\t */\r\n\tunsigned int pb_parallelism;\r\n\r\n\t/**\r\n\t * Callbacks to use for this push operation\r\n\t */\r\n\tgit_remote_callbacks callbacks;\r\n\r\n\t/**\r\n\t * Extra headers for this push operation\r\n\t */\r\n\tgit_strarray custom_headers;\r\n} git_push_options;\r\n```\r\n\r\nThe corresponding C# type is `GitPushOptions`\r\ndefined as\r\n```\r\nnamespace LibGit2Sharp.Core\r\n{\r\n    [StructLayout(LayoutKind.Sequential)]\r\n    internal class GitPushOptions\r\n    {\r\n        public int Version = 1;\r\n        public int PackbuilderDegreeOfParallelism;\r\n        public GitRemoteCallbacks RemoteCallbacks;\r\n    }\r\n}\r\n```\r\n\r\nNotice that `GitPushOptions` is missing the `custom_headers` member."},"comment":{"url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/comments/156255262","html_url":"https://github.com/libgit2/libgit2sharp/issues/1217#issuecomment-156255262","issue_url":"https://api.github.com/repos/libgit2/libgit2sharp/issues/1217","id":156255262,"user":{"login":"shiftkey","id":359239,"avatar_url":"https://avatars.githubusercontent.com/u/359239?v=3","gravatar_id":"","url":"https://api.github.com/users/shiftkey","html_url":"https://github.com/shiftkey","followers_url":"https://api.github.com/users/shiftkey/followers","following_url":"https://api.github.com/users/shiftkey/following{/other_user}","gists_url":"https://api.github.com/users/shiftkey/gists{/gist_id}","starred_url":"https://api.github.com/users/shiftkey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shiftkey/subscriptions","organizations_url":"https://api.github.com/users/shiftkey/orgs","repos_url":"https://api.github.com/users/shiftkey/repos","events_url":"https://api.github.com/users/shiftkey/events{/privacy}","received_events_url":"https://api.github.com/users/shiftkey/received_events","type":"User","site_admin":true},"created_at":"2015-11-12T22:22:00Z","updated_at":"2015-11-12T22:22:00Z","body":"> As a side note, GitHub Desktop cannot push to our private repo, but it doesn't report anything useful when it fails. I imagine this is the cause.\r\n\r\nWhat sort of server is your private repository on? GitHub? Or somewhere else? I'd love to confirm this is fixed for a future update."}}