{"thread":{"id":"31704","subject":"\"git am\" crash (builtin/apply.c:2108) + small repro","startedAt":"2012-10-01T18:33:42Z","lastAt":"2012-11-14T22:50:26Z","messageCount":7,"participants":["Alexey Spiridonov","Nguyen Thai Ngoc Duy","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"200281","messageId":"CAOKKMFG4JsNyMY7=SB6EuR8_GnpAu-ysH02J5pwD1cNzUgaieQ@mail.gmail.com","threadId":"31704","inReplyTo":null,"subject":"\"git am\" crash (builtin/apply.c:2108) + small repro","fromName":"Alexey Spiridonov","fromEmail":"snarkmaster@gmail.com","sentAt":"2012-10-01T18:33:42Z","receivedAt":"2012-10-01T18:33:42Z","isPatch":false,"sender":{"key":"snarkmaster@gmail.com","avatar":null},"body":"This reproduces in trunk, 1.7.8.4, and 1.7.9.5.\n\nI suspect this has to do with a whitespace + no trailing newline\nissues. The patch was generated by 1.7.9.5. I mangled it by hand to\nget it to be small, but the initial crash happened on a large,\nreal-world output of \"git format-patch\".\n\nError messages:\n\n~/GIT-AM-CRASH$ ../git/git am crashy.patch\nApplying: Git crash bug\ngit: builtin/apply.c:2108: update_pre_post_images: Assertion\n`fixed_preimage.nr == preimage->nr' failed.\n/home/lesha/GIT-AM-CRASH/../git/git-am: line 811: 23819 Aborted\n         git apply --index \"$dotest/patch\"\nPatch failed at 0001 Git crash bug\nThe copy of the patch that failed is found in:\n   /home/lesha/GIT-AM-CRASH/.git/rebase-apply/patch\nWhen you have resolved this problem, run \"git am --resolved\".\nIf you prefer to skip this patch, run \"git am --skip\" instead.\nTo restore the original branch and stop patching, run \"git am --abort\".\n\nRepro steps:\n\nmkdir GIT-AM-CRASH\ncd GIT-AM-CRASH\n# download files into this directory\ngit init .\nmkdir -p meep/spork\nmv __init__.py meep/spork\ngit add meep/spork/__init__.py\ngit ci -am 'moo'\ngit am crashy.patch\n\nHope this helps!\n\nAlexey\n\n\nFrom ab376a1d76b1605443b4d7eb9197be333b037f16 Mon Sep 17 00:00:00 2001\nFrom: lesha <snarkmaster@gmail.com>\nDate: Wed, 26 Sep 2012 10:58:43 -0700\nSubject: Git crash bug\n\n---\n\ndiff --git a/meep/spork/__init__.py b/meep/spork/__init__.py\nindex 9d869c9..ef120c7 100644\n--- a/meep/spork/__init__.py\n+++ b/meep/spork/__init__.py\n@@ -1,7 +1,9 @@\n from __future__ import absolute_import\n \n+from bar import Boo\n+\n from .baz import Bork\n \n-Boo.mooFooCow(Bork)\n+Boo.mooCow(Bork)\n   \n   \n\\ No newline at end of file\n"},{"id":"200401","messageId":"CACsJy8B9NDmGnopoFEAA0T4mgG+54npYnbb_d4tihRNB=xrGnw@mail.gmail.com","threadId":"31704","inReplyTo":"CAOKKMFG4JsNyMY7=SB6EuR8_GnpAu-ysH02J5pwD1cNzUgaieQ@mail.gmail.com","subject":"Re: \"git am\" crash (builtin/apply.c:2108) + small repro","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-10-03T11:27:07Z","receivedAt":"2012-10-03T11:27:07Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Oct 2, 2012 at 1:33 AM, Alexey Spiridonov <snarkmaster@gmail.com> wrote:\n> This reproduces in trunk, 1.7.8.4, and 1.7.9.5.\n\nfwiw, I cannot reproduce it (git-apply does not crash). I tried both\nversions and 1.8.0-rc1. Just in case the attached files are somehow\ncorrupted, this is sha1sum from my side:\n\n3d4711cd15d9617e0d3a52bbcd7def898c12c328  crashy.patch\nfd63cc32338823f216a6684ce5118a69113968c8  meep/spork/__init__.py\n\n> I suspect this has to do with a whitespace + no trailing newline\n> issues. The patch was generated by 1.7.9.5. I mangled it by hand to\n> get it to be small, but the initial crash happened on a large,\n> real-world output of \"git format-patch\".\n>\n> Error messages:\n>\n> ~/GIT-AM-CRASH$ ../git/git am crashy.patch\n> Applying: Git crash bug\n> git: builtin/apply.c:2108: update_pre_post_images: Assertion\n> `fixed_preimage.nr == preimage->nr' failed.\n> /home/lesha/GIT-AM-CRASH/../git/git-am: line 811: 23819 Aborted\n>          git apply --index \"$dotest/patch\"\n> Patch failed at 0001 Git crash bug\n> The copy of the patch that failed is found in:\n>    /home/lesha/GIT-AM-CRASH/.git/rebase-apply/patch\n> When you have resolved this problem, run \"git am --resolved\".\n> If you prefer to skip this patch, run \"git am --skip\" instead.\n> To restore the original branch and stop patching, run \"git am --abort\".\n>\n> Repro steps:\n>\n> mkdir GIT-AM-CRASH\n> cd GIT-AM-CRASH\n> # download files into this directory\n> git init .\n> mkdir -p meep/spork\n> mv __init__.py meep/spork\n> git add meep/spork/__init__.py\n> git ci -am 'moo'\n> git am crashy.patch\n>\n> Hope this helps!\n>\n> Alexey\n-- \nDuy\n"},{"id":"200429","messageId":"CAOKKMFFGz5Waz3OV4_uTgwDaL=S9NWAnLnACPzSkGpu_rrChvQ@mail.gmail.com","threadId":"31704","inReplyTo":"CACsJy8B9NDmGnopoFEAA0T4mgG+54npYnbb_d4tihRNB=xrGnw@mail.gmail.com","subject":"Re: \"git am\" crash (builtin/apply.c:2108) + small repro","fromName":"Alexey Spiridonov","fromEmail":"snarkmaster@gmail.com","sentAt":"2012-10-03T15:44:54Z","receivedAt":"2012-10-03T15:44:54Z","isPatch":false,"sender":{"key":"snarkmaster@gmail.com","avatar":null},"body":"Thanks a lot for trying this.\n\nMy hashes match. I just re-reproduced it on two flavors of Linux (64\nand 32-bit), with two different Git versions (see below). What\nplatform are you using?\n\n\nlesha@buryonka-ubuntu32:~$ mkdir GIT-AM-CRASH\nlesha@buryonka-ubuntu32:~$ cd GIT-AM-CRASH\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ mv ../crashy.patch ../__init__.py .\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ git init .\nInitialized empty Git repository in /home/lesha/GIT-AM-CRASH/.git/\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ mkdir -p meep/spork\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ mv __init__.py meep/spork\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ git add meep/spork/__init__.py\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ git ci -am 'moo'\n[master (root-commit) fa8f8fd] moo\n 1 file changed, 6 insertions(+)\n create mode 100644 meep/spork/__init__.py\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ git am crashy.patch\nApplying: Git crash bug\ngit: builtin/apply.c:1990: update_pre_post_images: Assertion\n`fixed_preimage.nr == preimage->nr' failed.\nAborted (core dumped)\nPatch failed at 0001 Git crash bug\nWhen you have resolved this problem run \"git am --resolved\".\nIf you would prefer to skip this patch, instead run \"git am --skip\".\nTo restore the original branch and stop patching run \"git am --abort\".\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ sha1\nsha1pass  sha1sum\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ sha1sum crashy.patch\nmeep/spork/__init__.py\n3d4711cd15d9617e0d3a52bbcd7def898c12c328  crashy.patch\nfd63cc32338823f216a6684ce5118a69113968c8  meep/spork/__init__.py\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ git --version\ngit version 1.7.9.5\nlesha@buryonka-ubuntu32:~/GIT-AM-CRASH$ uname -a\nLinux buryonka-ubuntu32 3.2.0-31-generic #50-Ubuntu SMP Fri Sep 7\n16:17:36 UTC 2012 i686 i686 i386 GNU/Linux\n\n\n[lesha@dev037 ~/GIT-AM-CRASH] git init .\nInitialized empty Git repository in /home/lesha/GIT-AM-CRASH/.git/\n[lesha@dev037 ~/GIT-AM-CRASH] mkdir -p meep/spork\n[lesha@dev037 ~/GIT-AM-CRASH] mv __init__.py meep/spork\n[lesha@dev037 ~/GIT-AM-CRASH] git add meep/spork/__init__.py\n[lesha@dev037 ~/GIT-AM-CRASH] git ci -am 'moo'\n[master (root-commit) 4c3fe5f] moo\n 1 files changed, 6 insertions(+), 0 deletions(-)\n create mode 100644 meep/spork/__init__.py\n[lesha@dev037 ~/GIT-AM-CRASH] git am crashy.patch\nApplying: Git crash bug\ngit: builtin/apply.c:1989: update_pre_post_images: Assertion\n`fixed_preimage.nr == preimage->nr' failed.\n/usr/libexec/git-core/git-am: line 789: 32074 Aborted\ngit apply --index \"$dotest/patch\"\nPatch failed at 0001 Git crash bug\nWhen you have resolved this problem run \"git am --resolved\".\nIf you would prefer to skip this patch, instead run \"git am --skip\".\nTo restore the original branch and stop patching run \"git am --abort\".\n[lesha@dev037 ~/GIT-AM-CRASH] git --version\ngit version 1.7.8.4\n[lesha@dev037 ~/GIT-AM-CRASH] uname -a\nLinux dev037 2.6.38.4 #63 SMP Mon Feb 13 16:22:45 PST 2012 x86_64\nx86_64 x86_64 GNU/Linux\n[lesha@dev037 ~/GIT-AM-CRASH] sha1sum crashy.patch meep/spork/__init__.py\n3d4711cd15d9617e0d3a52bbcd7def898c12c328  crashy.patch\nfd63cc32338823f216a6684ce5118a69113968c8  meep/spork/__init__.py\n\n-a\n\nOn Wed, Oct 3, 2012 at 4:27 AM, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:\n> On Tue, Oct 2, 2012 at 1:33 AM, Alexey Spiridonov <snarkmaster@gmail.com> wrote:\n>> This reproduces in trunk, 1.7.8.4, and 1.7.9.5.\n>\n> fwiw, I cannot reproduce it (git-apply does not crash). I tried both\n> versions and 1.8.0-rc1. Just in case the attached files are somehow\n> corrupted, this is sha1sum from my side:\n>\n> 3d4711cd15d9617e0d3a52bbcd7def898c12c328  crashy.patch\n> fd63cc32338823f216a6684ce5118a69113968c8  meep/spork/__init__.py\n>\n>> I suspect this has to do with a whitespace + no trailing newline\n>> issues. The patch was generated by 1.7.9.5. I mangled it by hand to\n>> get it to be small, but the initial crash happened on a large,\n>> real-world output of \"git format-patch\".\n>>\n>> Error messages:\n>>\n>> ~/GIT-AM-CRASH$ ../git/git am crashy.patch\n>> Applying: Git crash bug\n>> git: builtin/apply.c:2108: update_pre_post_images: Assertion\n>> `fixed_preimage.nr == preimage->nr' failed.\n>> /home/lesha/GIT-AM-CRASH/../git/git-am: line 811: 23819 Aborted\n>>          git apply --index \"$dotest/patch\"\n>> Patch failed at 0001 Git crash bug\n>> The copy of the patch that failed is found in:\n>>    /home/lesha/GIT-AM-CRASH/.git/rebase-apply/patch\n>> When you have resolved this problem, run \"git am --resolved\".\n>> If you prefer to skip this patch, run \"git am --skip\" instead.\n>> To restore the original branch and stop patching, run \"git am --abort\".\n>>\n>> Repro steps:\n>>\n>> mkdir GIT-AM-CRASH\n>> cd GIT-AM-CRASH\n>> # download files into this directory\n>> git init .\n>> mkdir -p meep/spork\n>> mv __init__.py meep/spork\n>> git add meep/spork/__init__.py\n>> git ci -am 'moo'\n>> git am crashy.patch\n>>\n>> Hope this helps!\n>>\n>> Alexey\n> --\n> Duy\n"},{"id":"200694","messageId":"CACsJy8B4xeLSDPC42JifZwC7VWTPRd2iZfnxtPhf7u3OzOm_6Q@mail.gmail.com","threadId":"31704","inReplyTo":"CAOKKMFFGz5Waz3OV4_uTgwDaL=S9NWAnLnACPzSkGpu_rrChvQ@mail.gmail.com","subject":"Re: \"git am\" crash (builtin/apply.c:2108) + small repro","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-10-07T03:33:22Z","receivedAt":"2012-10-07T03:33:22Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Oct 3, 2012 at 10:44 PM, Alexey Spiridonov\n<snarkmaster@gmail.com> wrote:\n> Thanks a lot for trying this.\n>\n> My hashes match. I just re-reproduced it on two flavors of Linux (64\n> and 32-bit), with two different Git versions (see below). What\n> platform are you using?\n\nx86, 32 bit. Perhaps it has something to do with your configuration\n(config files, hooks, attributes). Assuming you use standard\nrepository templates, you create new repo in your test so hooks and\nattributes are out. Is there anything suspicuous in \"git config -l\"?\n-- \nDuy\n"},{"id":"201074","messageId":"7vtxtz2x1g.fsf@alter.siamese.dyndns.org","threadId":"31704","inReplyTo":"CACsJy8B4xeLSDPC42JifZwC7VWTPRd2iZfnxtPhf7u3OzOm_6Q@mail.gmail.com","subject":"Re: \"git am\" crash (builtin/apply.c:2108) + small repro","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-10-12T21:35:55Z","receivedAt":"2012-10-12T21:35:55Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n\n> On Wed, Oct 3, 2012 at 10:44 PM, Alexey Spiridonov\n> <snarkmaster@gmail.com> wrote:\n>> Thanks a lot for trying this.\n>>\n>> My hashes match. I just re-reproduced it on two flavors of Linux (64\n>> and 32-bit), with two different Git versions (see below). What\n>> platform are you using?\n>\n> x86, 32 bit. Perhaps it has something to do with your configuration\n> (config files, hooks, attributes). Assuming you use standard\n> repository templates, you create new repo in your test so hooks and\n> attributes are out. Is there anything suspicuous in \"git config -l\"?\n\nI've never been a fan of update_pre_post_images().  I think I know\nwhat is going on (--whitespace=fix).  Will post a fix sometime\nlater.\n"},{"id":"202571","messageId":"CAOKKMFE=gwF4d+R2SD+3eRWqvZwkAt2hX8aPT8fvcwEZXiZbuQ@mail.gmail.com","threadId":"31704","inReplyTo":"7vlifb2tfp.fsf@alter.siamese.dyndns.org","subject":"Re: \"git am\" crash (builtin/apply.c:2108) + small repro","fromName":"Alexey Spiridonov","fromEmail":"snarkmaster@gmail.com","sentAt":"2012-11-05T22:55:17Z","receivedAt":"2012-11-05T22:55:17Z","isPatch":false,"sender":{"key":"snarkmaster@gmail.com","avatar":null},"body":"Thanks for looking into this, guys!\n\nI seem to run into this with some regularity, but my setting is\napply.whitespace=strip rather than 'fix'.\n\nIs there an obvious workaround?\n\nHere are my remaining settings, sanitized for file paths and URLs:\n\nsvn.rmdir=true\npush.default=upstream\ncolor.ui=auto\ncolor.diff=auto\ncolor.status=auto\ncolor.branch=auto\ncolor.interactive=auto\ncolor.branch.current=white blue bold\ncolor.branch.local=blue\ncolor.branch.remote=green\ncolor.diff.plain=white\ncolor.diff.meta=yellow bold\ncolor.diff.frag=magenta bold\ncolor.diff.old=red\ncolor.diff.new=green\ncolor.diff.whitespace=red blink\ncolor.status.added=yellow\ncolor.status.changed=green\ncolor.status.untracked=cyan\nsvn.followparent=true\nlog.date=relative\nblame.date=short\ndiff.renames=copies\ndiff.copies=true\ndiff.mnemonicprefix=true\napply.whitespace=strip\nmerge.tool=emerge\nstatus.relativepaths=true\nweb.browser=lynx\nrebase.stat=true\ncore.repositoryformatversion=0\ncore.filemode=true\ncore.bare=false\ncore.logallrefupdates=true\nrerere.enabled=true\nbranch.autosetuprebase=always\n\n-a\n\nOn Fri, Oct 12, 2012 at 3:53 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> I've never been a fan of update_pre_post_images().  I think I know\n>> what is going on (--whitespace=fix).  Will post a fix sometime\n>> later.\n>\n> It bisects down to 5166714 (apply: Allow blank context lines to\n> match beyond EOF, 2010-03-06).\n>\n> I do not like this patch at all (I _think_ it should somehow check\n> the corresponding postimage is sane when the \"ah, we ran out of\n> preimage because the caller fixed it to reduce trailing blank lines\"\n> case), but at least this should get the ball rolling.\n>\n> Björn, both of the changes involved are yours, so I am thinking that\n> you may be a good person to give a sanity check on this.  No need to\n> hurry, as this is not a recent regression and we are in a pre-release\n> freeze.\n>\n> Thanks.\n>\n> -- >8 --\n> Subject: apply.c:update_pre_post_images(): the preimage can be truncated\n>\n> 5166714 (apply: Allow blank context lines to match beyond EOF,\n> 2010-03-06) and then later 0c3ef98 (apply: Allow blank *trailing*\n> context lines to match beyond EOF, 2010-04-08) taught \"git apply\"\n> to trim new blank lines at the end in the patch text when matching\n> the contents being patched and the preimage recorded in the patch,\n> under --whitespace=fix mode.\n>\n> When a preimage is modified to match the current contents in\n> preparation for such a \"fixed\" patch application, the context lines\n> in the postimage must be updated to match (otherwise, it would\n> reintroduce whitespace breakages), and update_pre_post_images()\n> function is responsible for doing this.  However, this function was\n> not updated to take into account a case where the removal of\n> trailing blank lines reduces the number of lines in the preimage,\n> and triggered an assertion error.\n>\n> The logic to fix the postimage by copying the corrected context\n> lines from the preimage was not prepared to handle this case,\n> either, but it was protected by the assert() and only got exposed\n> when the assertion is corrected.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  builtin/apply.c | 23 +++++++++++++++++------\n>  1 file changed, 17 insertions(+), 6 deletions(-)\n>\n> diff --git c/builtin/apply.c w/builtin/apply.c\n> index 156b3ce..6c11e8b 100644\n> --- c/builtin/apply.c\n> +++ w/builtin/apply.c\n> @@ -2095,7 +2095,7 @@ static void update_pre_post_images(struct image *preimage,\n>                                    char *buf,\n>                                    size_t len, size_t postlen)\n>  {\n> -       int i, ctx;\n> +       int i, ctx, reduced;\n>         char *new, *old, *fixed;\n>         struct image fixed_preimage;\n>\n> @@ -2105,8 +2105,10 @@ static void update_pre_post_images(struct image *preimage,\n>          * free \"oldlines\".\n>          */\n>         prepare_image(&fixed_preimage, buf, len, 1);\n> -       assert(fixed_preimage.nr == preimage->nr);\n> -       for (i = 0; i < preimage->nr; i++)\n> +       assert(postlen\n> +              ? fixed_preimage.nr == preimage->nr\n> +              : fixed_preimage.nr <= preimage->nr);\n> +       for (i = 0; i < fixed_preimage.nr; i++)\n>                 fixed_preimage.line[i].flag = preimage->line[i].flag;\n>         free(preimage->line_allocated);\n>         *preimage = fixed_preimage;\n> @@ -2126,7 +2128,8 @@ static void update_pre_post_images(struct image *preimage,\n>         else\n>                 new = old;\n>         fixed = preimage->buf;\n> -       for (i = ctx = 0; i < postimage->nr; i++) {\n> +\n> +       for (i = reduced = ctx = 0; i < postimage->nr; i++) {\n>                 size_t len = postimage->line[i].len;\n>                 if (!(postimage->line[i].flag & LINE_COMMON)) {\n>                         /* an added line -- no counterparts in preimage */\n> @@ -2145,8 +2148,15 @@ static void update_pre_post_images(struct image *preimage,\n>                         fixed += preimage->line[ctx].len;\n>                         ctx++;\n>                 }\n> -               if (preimage->nr <= ctx)\n> -                       die(_(\"oops\"));\n> +\n> +               /*\n> +                * preimage is expected to run out, if the caller\n> +                * fixed addition of trailing blank lines.\n> +                */\n> +               if (preimage->nr <= ctx) {\n> +                       reduced++;\n> +                       continue;\n> +               }\n>\n>                 /* and copy it in, while fixing the line length */\n>                 len = preimage->line[ctx].len;\n> @@ -2159,6 +2169,7 @@ static void update_pre_post_images(struct image *preimage,\n>\n>         /* Fix the length of the whole thing */\n>         postimage->len = new - postimage->buf;\n> +       postimage->nr -= reduced;\n>  }\n>\n>  static int match_fragment(struct image *img,\n"},{"id":"203226","messageId":"7vd2zfajf1.fsf@alter.siamese.dyndns.org","threadId":"31704","inReplyTo":"CAOKKMFE=gwF4d+R2SD+3eRWqvZwkAt2hX8aPT8fvcwEZXiZbuQ@mail.gmail.com","subject":"Re: \"git am\" crash (builtin/apply.c:2108) + small repro","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-11-14T22:50:26Z","receivedAt":"2012-11-14T22:50:26Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexey Spiridonov <snarkmaster@gmail.com> writes:\n\n> Thanks for looking into this, guys!\n>\n> I seem to run into this with some regularity, but my setting is\n> apply.whitespace=strip rather than 'fix'.\n\n'strip' is an old synonym for 'fix'.\n"}]}