parsers: read sizes of metadata pair of obsolete marker at once
authorYuya Nishihara <yuya@tcha.org>
Sun, 11 Oct 2015 18:41:41 +0900
changeset 26590 473a63c45394
parent 26589 fb388aa26453
child 26591 042344313939
parsers: read sizes of metadata pair of obsolete marker at once This will make it easy to implement bound checking. Currently fm1readmarker() has no protection for corrupted obsstore and can cause infinite loop or out-of-bound reads.
mercurial/parsers.c
--- a/mercurial/parsers.c	Wed Oct 07 21:51:24 2015 -0700
+++ b/mercurial/parsers.c	Sun Oct 11 18:41:41 2015 +0900
@@ -2630,12 +2630,12 @@
 	}
 	for (i = 0; i < nmetadata; i++) {
 		PyObject *tmp, *left = NULL, *right = NULL;
-		Py_ssize_t metasize = (unsigned char)(*data++);
-		left = PyString_FromStringAndSize(meta, metasize);
-		meta += metasize;
-		metasize = (unsigned char)(*data++);
-		right = PyString_FromStringAndSize(meta, metasize);
-		meta += metasize;
+		Py_ssize_t leftsize = (unsigned char)(*data++);
+		Py_ssize_t rightsize = (unsigned char)(*data++);
+		left = PyString_FromStringAndSize(meta, leftsize);
+		meta += leftsize;
+		right = PyString_FromStringAndSize(meta, rightsize);
+		meta += rightsize;
 		tmp = PyTuple_New(2);
 		if (!left || !right || !tmp) {
 			Py_XDECREF(left);