sparse-revlog: protect C code against delta chain including nullrev
authorBoris Feld <boris.feld@octobus.net>
Fri, 14 Dec 2018 17:25:41 +0100
changeset 40976 2e305e54eae3
parent 40975 c6939b353ebd
child 40977 98a0fbda8739
sparse-revlog: protect C code against delta chain including nullrev For unclear reasons, some repositories include nullrev (-1). Re-computing delta for such repo remove nullrev from all chain, so some older versions have been creating them. This currently raise an IndexError with the new C code doing chain slicing as it expect all item to be positive. Both python and C code for reading delta chain preserve nullrev, and the Python code for chain slicing handle the case fine. So we take the safe route and make the new C code works fine in that case.
mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c	Fri Dec 14 17:24:44 2018 +0100
+++ b/mercurial/cext/revlog.c	Fri Dec 14 17:25:41 2018 +0100
@@ -1229,7 +1229,7 @@
 		if (revnum == -1 && PyErr_Occurred()) {
 			goto bail;
 		}
-		if (revnum < 0 || revnum >= idxlen) {
+		if (revnum < nullrev || revnum >= idxlen) {
 			PyErr_Format(PyExc_IndexError,
 			             "index out of range: %zd", revnum);
 			goto bail;