Mercurial > public > mercurial-scm > hg-stable
diff mercurial/patch.py @ 37573:49b82cdb5983
patch: error out if reached to EOF while reading hunk
This was where out-of-bounds read occurred in old C extension.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 09 Apr 2018 21:06:46 +0900 |
parents | 0ea8b9576d7c |
children | a1bcc7ff0eac |
line wrap: on
line diff
--- a/mercurial/patch.py Mon Apr 09 20:55:05 2018 +0900 +++ b/mercurial/patch.py Mon Apr 09 21:06:46 2018 +0900 @@ -1254,8 +1254,11 @@ self.lenb = int(self.lenb) self.starta = int(self.starta) self.startb = int(self.startb) - diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb, self.a, - self.b) + try: + diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb, + self.a, self.b) + except error.ParseError as e: + raise PatchError(_("bad hunk #%d: %s") % (self.number, e)) # if we hit eof before finishing out the hunk, the last line will # be zero length. Lets try to fix it up. while len(self.hunk[-1]) == 0: