{"thread":{"id":"17693","subject":"A little mystery - crash caused by empty commit message.","startedAt":"2009-02-10T11:15:54Z","lastAt":"2009-02-16T10:18:06Z","messageCount":6,"participants":["Tor Arvid Lund","Jeff King","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"103975","messageId":"1a6be5fa0902100315q554dc457j8c8476d3f59a314f@mail.gmail.com","threadId":"17693","inReplyTo":null,"subject":"A little mystery - crash caused by empty commit message.","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2009-02-10T11:15:54Z","receivedAt":"2009-02-10T11:15:54Z","isPatch":false,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"Hi, all.\n\nSo - I started noticing a problem where for instance \"git log\" or \"git\nbranch -av\" would crash in one of my repositories. My environment is\nWindows Vista x64, using msysgit. I have compiled several versions of\ngit, but I think I had version 1.6.0.3 then this problem arose. When\nthe crash occurred, Windows would just pop up a dialog window saying\n\"git.exe has stopped working\". So I tried running it with gdb, which\ntold me there was a segfault in strchr() but no more. Git is built\nwith debug symbols (-g), so I am guessing this may be a problem with\nmy msysgit environment (maybe in conjunction with 64-bit Vista) or\nsomething. But I don't really know what I'm talking about, and it is\nanother topic anyway...\n\nThen I tried copying the repository to a linux box and tried gdb\nthere. Much better. strchr(line, '\\n') is called in pretty.c in the\nget_header function. For one of the commits, the 'line' parameter was\nNULL, so I managed to make it not crash with this little patch:\n\ndiff --git a/pretty.c b/pretty.c\nindex 8d4dbc9..1b2d097 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -230,6 +230,8 @@ static char *get_header(const struct commit\n*commit, const char *key)\n       const char *line = commit->buffer;\n\n       for (;;) {\n+               if (line == NULL)\n+                       return NULL;\n               const char *eol = strchr(line, '\\n'), *next;\n\n               if (line == eol)\n\n\n\nThe result from \"git log\" for me is then:\n\n...\ncommit 6a1ac5bc05b2cdd276c7f8a39565681f9d8017d7\n<normal output>\n\ncommit f67f77edf06bbcebabf430735c751245a4b70f14\nAuthor: Tor Arvid Lund <toral@qsystems.no>\nDate:   Thu Feb 5 17:47:09 2009 +0100\n\ncommit 6d109492008c68d28af821b96b82f807f338caf6\n<normal output>\n...\n\nThat is - a handful of commits that are output \"normally\", followed by\none commit where the message is just blank, and then more \"normal\"\noutput... By the way - I tried running git fsck --full --strict, and\nit did not report any errors (just the \"common\" list of dangling blobs\nand such...\n\nBut the question is then - how did I manage to get my repository in\nthis state? The commit in question was made by me - I know I entered a\nmessage when I committed it. I can even find the commit *with* the\noriginal commit message in another branch... I am sorry to say that my\nmemory fails me, so I cannot remember all the times I may have moved\ncommits around, rebased, etc. I do such things often, as I use git-p4\nto communicate with the \"official company repo\" (and because its so\nnice :)). I don't know the core git code well, but when I'm in the\nmood for speculation, I feel like a rebase or a cherry-pick must have\nbeen the reason for this to have happened...\n\nWell - I just thought I should tell you all about it. My simple little\npatch makes it \"not crash\", but it should maybe report an error or\nwarning to the user - as something is most likely wrong somewhere.\n\n-Tor Arvid-\n"},{"id":"103979","messageId":"20090210113234.GE12089@coredump.intra.peff.net","threadId":"17693","inReplyTo":"1a6be5fa0902100315q554dc457j8c8476d3f59a314f@mail.gmail.com","subject":"Re: A little mystery - crash caused by empty commit message.","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-02-10T11:32:34Z","receivedAt":"2009-02-10T11:32:34Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Feb 10, 2009 at 12:15:54PM +0100, Tor Arvid Lund wrote:\n\n> Then I tried copying the repository to a linux box and tried gdb\n> there. Much better. strchr(line, '\\n') is called in pretty.c in the\n> get_header function. For one of the commits, the 'line' parameter was\n> NULL, so I managed to make it not crash with this little patch:\n> \n> diff --git a/pretty.c b/pretty.c\n> index 8d4dbc9..1b2d097 100644\n> --- a/pretty.c\n> +++ b/pretty.c\n> @@ -230,6 +230,8 @@ static char *get_header(const struct commit\n> *commit, const char *key)\n>        const char *line = commit->buffer;\n> \n>        for (;;) {\n> +               if (line == NULL)\n> +                       return NULL;\n>                const char *eol = strchr(line, '\\n'), *next;\n> \n>                if (line == eol)\n\nHmm. I can't reproduce the crash here with an empty commit message. I\ntried:\n\n  mkdir repo && cd repo && git init &&\n  touch file && git add . &&\n  tree=`git write-tree`\n  commit=`git commit-tree $tree </dev/null`\n  git update-ref HEAD $commit\n  git log\n\nAre you sure it's truly an _empty_ commit message? Can you try\n\n  git cat-file commit f67f77edf06bbcebabf430735c751245a4b70f14\n\nand look at the result with xxd, hd, or similar.\n\n> But the question is then - how did I manage to get my repository in\n> this state? The commit in question was made by me - I know I entered a\n> message when I committed it. I can even find the commit *with* the\n> original commit message in another branch... I am sorry to say that my\n\nIt _is_ generally hard to get an empty commit message using \"git\ncommit\". But it's possible there is a bug in cherry-pick, rebase, or\nsome ohter low-level tool that accidentally erased your message\nas the commit was moved.\n\n-Peff\n"},{"id":"103982","messageId":"4991691E.6010808@viscovery.net","threadId":"17693","inReplyTo":"20090210113234.GE12089@coredump.intra.peff.net","subject":"Re: A little mystery - crash caused by empty commit message.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-02-10T11:46:38Z","receivedAt":"2009-02-10T11:46:38Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Jeff King schrieb:\n> It _is_ generally hard to get an empty commit message using \"git\n> commit\". But it's possible there is a bug in cherry-pick, rebase, or\n> some ohter low-level tool that accidentally erased your message\n> as the commit was moved.\n\nSince this is on Windows, chances are that this is an encoding issue. If\nyou have non-ASCII in the commit message, but i18n.commitEncoding is\nunset, then you can introduce invalid UTF8 sequences easily. This could\nconfuse one of the pipelines (rebase, am, cherry-pick, etc).\n\nYou should set\n\n\tgit config i18n.commitencoding cp1252\n\n(or whatever is appropriate for you locale). I even have\n\n\tgit config i18n.logoutputencoding cp850\n\nso that I see correct umlauts if I happen to run git log without a pager\nin CMD ;) (I rarely do that, though.)\n\n-- Hannes\n"},{"id":"103998","messageId":"1a6be5fa0902100458w246f2bfeu5c0c303d18d17a3b@mail.gmail.com","threadId":"17693","inReplyTo":"20090210113234.GE12089@coredump.intra.peff.net","subject":"Re: A little mystery - crash caused by empty commit message.","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2009-02-10T12:58:43Z","receivedAt":"2009-02-10T12:58:43Z","isPatch":false,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"On Tue, Feb 10, 2009 at 12:32 PM, Jeff King <peff@peff.net> wrote:\n> Are you sure it's truly an _empty_ commit message? Can you try\n>\n>  git cat-file commit f67f77edf06bbcebabf430735c751245a4b70f14\n>\n> and look at the result with xxd, hd, or similar.\n\nCool. You are correct. It is not empty after all. I ran git cat-file\non that commit, and on the \"same\" commit on the branch where I did not\nsee the problem. The correct one looks like:\n\n<start>\ntree c5d2063a9b21de1f84240e4b9c0e40a44f0357b6\nparent 6d109492008c68d28af821b96b82f807f338caf6\nauthor Tor Arvid Lund <toral@qsystems.no> 1233852429 +0100\ncommitter Tor Arvid Lund <toral@qsystems.no> 1233852429 +0100\n\n[HIA] Log exception when serializing fails.\n\n[git-p4: depot-paths = \"//Heads/Dev/MarkII/Main/\": change = 19233]\n<stop>\n\nSo - after the \"+0100\" on the committer line, hd tells me (as\nexpected) that I have 0a 0a before \"[HIA]\". On the \"faulty\" commit I,\nfor some reason, have 0a 00 instead. I do not understand why, but I\nguess strchr will return NULL when \"\\0[HIA].....\" is passed to it, and\nsegfault on the next iteration.\n\nSo - I am no closer to understanding what got me to this state, but\nyour reply was helpful anyway, thanks :-)\n\n-Tor Arvid-\n"},{"id":"104025","messageId":"20090210153048.GA17660@coredump.intra.peff.net","threadId":"17693","inReplyTo":"1a6be5fa0902100458w246f2bfeu5c0c303d18d17a3b@mail.gmail.com","subject":"Re: A little mystery - crash caused by empty commit message.","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-02-10T15:30:48Z","receivedAt":"2009-02-10T15:30:48Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Feb 10, 2009 at 01:58:43PM +0100, Tor Arvid Lund wrote:\n\n> So - after the \"+0100\" on the committer line, hd tells me (as\n> expected) that I have 0a 0a before \"[HIA]\". On the \"faulty\" commit I,\n> for some reason, have 0a 00 instead. I do not understand why, but I\n> guess strchr will return NULL when \"\\0[HIA].....\" is passed to it, and\n> segfault on the next iteration.\n> \n> So - I am no closer to understanding what got me to this state, but\n> your reply was helpful anyway, thanks :-)\n\nWell, it certainly seems like a bug in one of the history-rewriting\nprograms. Can you try rebasing, cherry-picking, etc on the original\nversion of the commit to see if you can reproduce the breakage?\n\n-Peff\n"},{"id":"104927","messageId":"1a6be5fa0902160218r65965c18nd3ee90d040702b9@mail.gmail.com","threadId":"17693","inReplyTo":"20090210153048.GA17660@coredump.intra.peff.net","subject":"Re: A little mystery - crash caused by empty commit message.","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2009-02-16T10:18:06Z","receivedAt":"2009-02-16T10:18:06Z","isPatch":false,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"On Tue, Feb 10, 2009 at 4:30 PM, Jeff King <peff@peff.net> wrote:\n> On Tue, Feb 10, 2009 at 01:58:43PM +0100, Tor Arvid Lund wrote:\n>\n>> So - after the \"+0100\" on the committer line, hd tells me (as\n>> expected) that I have 0a 0a before \"[HIA]\". On the \"faulty\" commit I,\n>> for some reason, have 0a 00 instead. I do not understand why, but I\n>> guess strchr will return NULL when \"\\0[HIA].....\" is passed to it, and\n>> segfault on the next iteration.\n>>\n>> So - I am no closer to understanding what got me to this state, but\n>> your reply was helpful anyway, thanks :-)\n>\n> Well, it certainly seems like a bug in one of the history-rewriting\n> programs. Can you try rebasing, cherry-picking, etc on the original\n> version of the commit to see if you can reproduce the breakage?\n\nHi, I haven't had much time to test this thoroughly, but my primary\nsuspect is now git-p4 in conjunction with python v2.6, which I\nrecently installed. I will try to find some time to investigate\nfurther, and let you all know for sure.\n\n-Tor Arvid-\n"}]}