{"thread":{"id":"6537","subject":"[PATCH] diffcore-pickaxe: fix infinite loop on zero-length needle","startedAt":"2007-01-26T04:48:58Z","lastAt":"2007-01-26T05:16:23Z","messageCount":3,"participants":["Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"32677","messageId":"20070126044858.GA8653@coredump.intra.peff.net","threadId":"6537","inReplyTo":null,"subject":"[PATCH] diffcore-pickaxe: fix infinite loop on zero-length needle","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-01-26T04:48:58Z","receivedAt":"2007-01-26T04:48:58Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The \"contains\" algorithm runs into an infinite loop if the needle string\nhas zero length. The loop could be modified to handle this, but it makes\nmore sense to simply have an empty needle return no matches. Thus, a\ncommand like\n  git log -S\nproduces no output.\n\nWe place the check at the top of the function so that we get the same\nresults with or without --pickaxe-regex. Note that until now,\n  git log -S --pickaxe-regex\nwould match everything, not nothing.\n\nArguably, an empty pickaxe string should simply produce an error\nmessage; however, this is still a useful assertion to add to the\nalgorithm at this layer of the code.\n\nNoticed by Bill Lear.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nOn Thu, Jan 25, 2007 at 06:06:51PM -0600, Bill Lear wrote:\n\n> git log -S --check foo\n>\n> and the thing went off into outer space.  Now at over 2 1/2 minutes of\n> CPU time on my 2 Ghz Opteron box...\n\n diffcore-pickaxe.c |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c\nindex de44ada..286919e 100644\n--- a/diffcore-pickaxe.c\n+++ b/diffcore-pickaxe.c\n@@ -14,6 +14,8 @@ static unsigned int contains(struct diff_filespec *one,\n \tconst char *data;\n \tif (diff_populate_filespec(one, 0))\n \t\treturn 0;\n+\tif (!len)\n+\t\treturn 0;\n \n \tsz = one->size;\n \tdata = one->data;\n-- \n1.5.0.rc2.gccd57\n"},{"id":"32678","messageId":"20070126045639.GA9260@coredump.intra.peff.net","threadId":"6537","inReplyTo":"20070126044858.GA8653@coredump.intra.peff.net","subject":"Re: [PATCH] diffcore-pickaxe: fix infinite loop on zero-length needle","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-01-26T04:56:40Z","receivedAt":"2007-01-26T04:56:40Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jan 25, 2007 at 11:48:58PM -0500, Jeff King wrote:\n\n> has zero length. The loop could be modified to handle this, but it makes\n> more sense to simply have an empty needle return no matches. Thus, a\n> command like\n>   git log -S\n> produces no output.\n> \n> We place the check at the top of the function so that we get the same\n> results with or without --pickaxe-regex. Note that until now,\n>   git log -S --pickaxe-regex\n> would match everything, not nothing.\n\nMy assumption is that nobody is really depending on this behavior\n(since, after all, without --pickaxe-regex it caused an infinite loop!).\nIf you want to maintain consistency, the conditional should simply\nreturn 1 instead of 0 (no callers of contains() actually care about the\ncount value).\n\n-Peff\n"},{"id":"32680","messageId":"7vtzye2wrc.fsf@assigned-by-dhcp.cox.net","threadId":"6537","inReplyTo":"20070126044858.GA8653@coredump.intra.peff.net","subject":"Re: [PATCH] diffcore-pickaxe: fix infinite loop on zero-length needle","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-26T05:16:23Z","receivedAt":"2007-01-26T05:16:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}