# HG changeset patch # User Bryan O'Sullivan # Date 1428333807 25200 # Node ID 2262d7bc469edf95a6c58c4833e8474a20a95281 # Parent 1e05f11619bb4256e85fac62cf71c0e3e4639d2e parsers: check for memory allocation overflows more carefully diff -r 1e05f11619bb -r 2262d7bc469e mercurial/parsers.c --- a/mercurial/parsers.c Sat Apr 04 11:27:15 2015 +0200 +++ b/mercurial/parsers.c Mon Apr 06 08:23:27 2015 -0700 @@ -1319,6 +1319,11 @@ static int nt_new(indexObject *self) { if (self->ntlength == self->ntcapacity) { + if (self->ntcapacity >= INT_MAX / (sizeof(nodetree) * 2)) { + PyErr_SetString(PyExc_MemoryError, + "overflow in nt_new"); + return -1; + } self->ntcapacity *= 2; self->nt = realloc(self->nt, self->ntcapacity * sizeof(nodetree)); @@ -1380,7 +1385,7 @@ static int nt_init(indexObject *self) { if (self->nt == NULL) { - if (self->raw_length > INT_MAX) { + if (self->raw_length > INT_MAX / sizeof(nodetree)) { PyErr_SetString(PyExc_ValueError, "overflow in nt_init"); return -1; }