Author: Nicolas Truessel <ntrues...@njsm.de>
Branch: quad-color-gc
Changeset: r86454:92eeddd8d966
Date: 2016-08-23 18:02 +0200
http://bitbucket.org/pypy/pypy/changeset/92eeddd8d966/

Log:    Detect overflow errors in malloc_varsize_clear

diff --git a/rpython/memory/gc/qcgc.py b/rpython/memory/gc/qcgc.py
--- a/rpython/memory/gc/qcgc.py
+++ b/rpython/memory/gc/qcgc.py
@@ -2,6 +2,7 @@
 from rpython.rtyper.lltypesystem import rffi, lltype, llgroup, llmemory, 
llarena
 from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.rlib.debug import ll_assert
+from rpython.rlib.rarithmetic import ovfcheck
 
 class QCGC(GCBase):
     _alloc_flavor_ = "raw"
@@ -43,8 +44,15 @@
 
     def malloc_varsize_clear(self, typeid, length, size, itemsize,
                              offset_to_length):
-        totalsize = size + itemsize * length
-        #totalsize = llarena.round_up_for_allocation(totalsize)
+        if length < 0:
+            raise MemoryError
+        #
+        try:
+            varsize = ovfcheck(itemsize * length)
+            totalsize = ovfcheck(size + varsize)
+        except OverflowError:
+            raise MemoryError
+        #
         obj = llop.qcgc_allocate(llmemory.Address, totalsize)
         self.init_gc_object(obj, typeid)
         (obj + offset_to_length).signed[0] = length
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to