Git development
 help / color / mirror / Atom feed
* [PATCH] diffcore-pickaxe: fix infinite loop on zero-length needle
@ 2007-01-26  4:48 Jeff King
  2007-01-26  4:56 ` Jeff King
  2007-01-26  5:16 ` Junio C Hamano
  0 siblings, 2 replies; 3+ messages in thread
From: Jeff King @ 2007-01-26  4:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Bill Lear, git

The "contains" algorithm runs into an infinite loop if the needle string
has zero length. The loop could be modified to handle this, but it makes
more sense to simply have an empty needle return no matches. Thus, a
command like
  git log -S
produces no output.

We place the check at the top of the function so that we get the same
results with or without --pickaxe-regex. Note that until now,
  git log -S --pickaxe-regex
would match everything, not nothing.

Arguably, an empty pickaxe string should simply produce an error
message; however, this is still a useful assertion to add to the
algorithm at this layer of the code.

Noticed by Bill Lear.

Signed-off-by: Jeff King <peff@peff.net>
---
On Thu, Jan 25, 2007 at 06:06:51PM -0600, Bill Lear wrote:

> git log -S --check foo
>
> and the thing went off into outer space.  Now at over 2 1/2 minutes of
> CPU time on my 2 Ghz Opteron box...

 diffcore-pickaxe.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index de44ada..286919e 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -14,6 +14,8 @@ static unsigned int contains(struct diff_filespec *one,
 	const char *data;
 	if (diff_populate_filespec(one, 0))
 		return 0;
+	if (!len)
+		return 0;
 
 	sz = one->size;
 	data = one->data;
-- 
1.5.0.rc2.gccd57

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] diffcore-pickaxe: fix infinite loop on zero-length needle
  2007-01-26  4:48 [PATCH] diffcore-pickaxe: fix infinite loop on zero-length needle Jeff King
@ 2007-01-26  4:56 ` Jeff King
  2007-01-26  5:16 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2007-01-26  4:56 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Thu, Jan 25, 2007 at 11:48:58PM -0500, Jeff King wrote:

> has zero length. The loop could be modified to handle this, but it makes
> more sense to simply have an empty needle return no matches. Thus, a
> command like
>   git log -S
> produces no output.
> 
> We place the check at the top of the function so that we get the same
> results with or without --pickaxe-regex. Note that until now,
>   git log -S --pickaxe-regex
> would match everything, not nothing.

My assumption is that nobody is really depending on this behavior
(since, after all, without --pickaxe-regex it caused an infinite loop!).
If you want to maintain consistency, the conditional should simply
return 1 instead of 0 (no callers of contains() actually care about the
count value).

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] diffcore-pickaxe: fix infinite loop on zero-length needle
  2007-01-26  4:48 [PATCH] diffcore-pickaxe: fix infinite loop on zero-length needle Jeff King
  2007-01-26  4:56 ` Jeff King
@ 2007-01-26  5:16 ` Junio C Hamano
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2007-01-26  5:16 UTC (permalink / raw)
  To: Jeff King; +Cc: Bill Lear, git

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-01-26  5:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-26  4:48 [PATCH] diffcore-pickaxe: fix infinite loop on zero-length needle Jeff King
2007-01-26  4:56 ` Jeff King
2007-01-26  5:16 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox