diff mercurial/parsers.c @ 26590:473a63c45394

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.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 11 Oct 2015 18:41:41 +0900
parents 46605888faf3
children 042344313939
line wrap: on
line diff
--- 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);