mercurial/cext/revlog.c
changeset 40704 7da3729d4b45
parent 40703 d5b300ec2e89
child 40705 4ec6a24029d2
--- a/mercurial/cext/revlog.c	Tue Nov 20 14:49:18 2018 +0000
+++ b/mercurial/cext/revlog.c	Fri Nov 09 18:42:58 2018 +0100
@@ -10,6 +10,7 @@
 #include <Python.h>
 #include <assert.h>
 #include <ctype.h>
+#include <limits.h>
 #include <stddef.h>
 #include <string.h>
 
@@ -219,6 +220,31 @@
 	return (int64_t)(offset >> 16);
 }
 
+static inline int index_get_length(indexObject *self, Py_ssize_t rev)
+{
+	if (rev >= self->length) {
+		PyObject *tuple;
+		PyObject *pylong;
+		long ret;
+		tuple = PyList_GET_ITEM(self->added, rev - self->length);
+		pylong = PyTuple_GET_ITEM(tuple, 1);
+		ret = PyInt_AsLong(pylong);
+		if (ret == -1 && PyErr_Occurred()) {
+			return -1;
+		}
+		if (ret < 0 || ret > (long)INT_MAX) {
+			PyErr_Format(PyExc_OverflowError,
+			             "revlog entry size out of bound (%ld)",
+			             ret);
+			return -1;
+		}
+		return (int)ret;
+	} else {
+		const char *data = index_deref(self, rev);
+		return (int)getbe32(data + 8);
+	}
+}
+
 /*
  * RevlogNG format (all in big endian, data may be inlined):
  *    6 bytes: offset