diff --git a/mercurial/mpatch.c b/mercurial/mpatch.c --- a/mercurial/mpatch.c +++ b/mercurial/mpatch.c @@ -248,7 +248,7 @@ int mpatch_apply(char *buf, const char * char *p = buf; while (f != l->tail) { - if (f->start < last || f->end > len) { + if (f->start < last || f->end > len || last < 0) { return MPATCH_ERR_INVALID_PATCH; } memcpy(p, orig + last, f->start - last); @@ -258,6 +258,9 @@ int mpatch_apply(char *buf, const char * p += f->len; f++; } + if (last < 0) { + return MPATCH_ERR_INVALID_PATCH; + } memcpy(p, orig + last, len - last); return 0; }