Patchwork D11334: revlog: fix type confusion with sidedata_comp_len (issue 6580)

login
register
mail settings
Submitter phabricator
Date Aug. 24, 2021, 10:45 a.m.
Message ID <differential-rev-PHID-DREV-w6jizpaqoaxdalrw4zyy-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49649/
State Superseded
Headers show

Comments

phabricator - Aug. 24, 2021, 10:45 a.m.
jcristau created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The format string uses "i" (int) for sidedata_comp_len, so we shouldn't
  be passing a pointer to Py_ssize_t to PyArg_ParseTuple.  On 64-bit
  big-endian, this would result in python only writing to the upper 32
  bits, and things go downhill from there.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D11334

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS




To: jcristau, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -452,9 +452,9 @@ 
 static PyObject *index_append(indexObject *self, PyObject *obj)
 {
 	uint64_t offset_flags, sidedata_offset;
-	int rev, comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2;
+	int rev, comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2, sidedata_comp_len;
 	char data_comp_mode, sidedata_comp_mode;
-	Py_ssize_t c_node_id_len, sidedata_comp_len;
+	Py_ssize_t c_node_id_len;
 	const char *c_node_id;
 	char comp_field;
 	char *data;
@@ -534,9 +534,8 @@ 
 static PyObject *index_replace_sidedata_info(indexObject *self, PyObject *args)
 {
 	uint64_t offset_flags, sidedata_offset;
-	int rev;
+	int rev, sidedata_comp_len;
 	char comp_mode;
-	Py_ssize_t sidedata_comp_len;
 	char *data;
 #if LONG_MAX == 0x7fffffffL
 	const char *const sidedata_format = PY23("nKiKB", "nKiKB");