diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1014,9 +1014,9 @@ class hunk(object): oldstart = self.starta + top newstart = self.startb + top # zero length hunk ranges already have their start decremented - if self.lena: + if self.lena and oldstart > 0: oldstart -= 1 - if self.lenb: + if self.lenb and newstart > 0: newstart -= 1 return old, oldstart, new, newstart diff --git a/tests/test-import.t b/tests/test-import.t --- a/tests/test-import.t +++ b/tests/test-import.t @@ -997,6 +997,26 @@ import a unified diff with no lines of c c3 c4 +no segfault while importing a unified diff which start line is zero but chunk +size is non-zero + + $ hg init startlinezero + $ cd startlinezero + $ echo foo > foo + $ hg commit -Amfoo + adding foo + + $ hg import --no-commit - << EOF + > diff a/foo b/foo + > --- a/foo + > +++ b/foo + > @@ -0,1 +0,1 @@ + > foo + > EOF + applying patch from stdin + + $ cd .. + Test corner case involving fuzz and skew $ hg init morecornercases