From patchwork Thu Dec 4 18:53:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: parsers: ensure revlog index node tree is initialized before insertion From: adgar@google.com X-Patchwork-Id: 7008 Message-Id: <4c8cd4678e1cf6992b7d.1417719221@adgar.nyc.corp.google.com> To: mercurial-devel@selenic.com Date: Thu, 04 Dec 2014 13:53:41 -0500 # HG changeset patch # User Mike Edgar # Date 1417712522 18000 # Thu Dec 04 12:02:02 2014 -0500 # Node ID 4c8cd4678e1cf6992b7d0a07b87b60775f0dc2c0 # Parent c237499a7fba65c88a2da721a22b66df4f39cf4e parsers: ensure revlog index node tree is initialized before insertion Currently, the revlog index C implementation assumes its node tree will be initialized before a new element is inserted by revnum. For example, revlog.py executes 'self.index.insert(-1, e)' in _addrevision(). This is only safe because the node tree has been initialized by a "node in self.nodemap" check made in addrevision(). (For context, this was discovered while developing an experimental revlog mixin which stores "elided nodes" via a separate code path from _addrevision(); that new code path segfaults without this patch.) diff -r c237499a7fba -r 4c8cd4678e1c mercurial/parsers.c --- a/mercurial/parsers.c Wed Dec 03 22:56:42 2014 +0900 +++ b/mercurial/parsers.c Thu Dec 04 12:02:02 2014 -0500 @@ -1978,6 +1978,9 @@ PyErr_SetString(PyExc_ValueError, "rev out of range"); return -1; } + + if (nt_init(self) == -1) + return -1; return nt_insert(self, node, (int)rev); }