comparison 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
comparison
equal deleted inserted replaced
37572:c6b8d614690a 37573:49b82cdb5983
1252 self.lenb = 1 1252 self.lenb = 1
1253 else: 1253 else:
1254 self.lenb = int(self.lenb) 1254 self.lenb = int(self.lenb)
1255 self.starta = int(self.starta) 1255 self.starta = int(self.starta)
1256 self.startb = int(self.startb) 1256 self.startb = int(self.startb)
1257 diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb, self.a, 1257 try:
1258 self.b) 1258 diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb,
1259 self.a, self.b)
1260 except error.ParseError as e:
1261 raise PatchError(_("bad hunk #%d: %s") % (self.number, e))
1259 # if we hit eof before finishing out the hunk, the last line will 1262 # if we hit eof before finishing out the hunk, the last line will
1260 # be zero length. Lets try to fix it up. 1263 # be zero length. Lets try to fix it up.
1261 while len(self.hunk[-1]) == 0: 1264 while len(self.hunk[-1]) == 0:
1262 del self.hunk[-1] 1265 del self.hunk[-1]
1263 del self.a[-1] 1266 del self.a[-1]