[Python-Dev] can this overflow (list insertion)? (original) (raw)

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Sun, 13 Aug 2000 00:24:39 +0200 (CEST)


Trent Mick wrote:

[listobject.c/ins1()] ... self->obitem = items; self->obsize++; <-------------- can this overflow? return 0; }

In the case of sizeof(int) < sizeof(void*), can this overflow. I have a small_ _patch to text self->obsize against INTMAX and I was going to submit it but I am not so sure that overflow is not checked by some other mechanism for list insert.

+0.

It could overflow but if it does, this is a bad sign about using a list for such huge amount of data.

And this is the second time in a week that I see an attempt to introduce a bogus counter due to post-increments embedded in an if statement!

Is it or was this relying on sizeof(obsize) == sizeof(void*), hence a list being able to hold as many items as there is addressable memory?

scared-to-patch-ly yours, Trent

And you're right

proposed patch: *** python/dist/src/Objects/listobject.c Fri Aug 11 16:25:08 2000 --- Python/dist/src/Objects/listobject.c Fri Aug 11 16:25:36 2000 *************** *** 149,155 **** PyINCREF(v); items[where] = v; self->obitem = items; ! self->obsize++; return 0; } --- 149,159 ---- PyINCREF(v); items[where] = v; self->obitem = items; ! if (self->obsize++ == INTMAX) { ! PyErrSetString(PyExcOverflowError, ! "cannot add more objects to list"); ! return -1; ! } return 0; }

-- Trent Mick TrentM@ActiveState.com


Python-Dev mailing list Python-Dev@python.org http://www.python.org/mailman/listinfo/python-dev

-- Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252