[pypy-commit] lang-smalltalk default: (cfbolz, timfel) fix not-aligned access into compiled method

timfel noreply at buildbot.pypy.org
Mon Feb 18 16:12:52 CET 2013


Author: Tim Felgentreff <timfelgentreff at gmail.com>
Branch: 
Changeset: r37:ea768f7676bc
Date: 2013-02-18 15:57 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/ea768f7676bc/

Log:	(cfbolz, timfel) fix not-aligned access into compiled method

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -614,11 +614,14 @@
             return space.wrap_int(ord(self.bytes[index0]))
         
     def atput0(self, space, index0, w_value):
-        if index0 <= self.getliteralsize():
+        byteoffset = self.getliteralsize() + self.headersize()
+        if index0 < byteoffset:
+            if index0 % constants.BYTES_PER_WORD != 0:
+                raise error.PrimitiveFailedError("improper store")
             self.literalatput0(space, index0 / constants.BYTES_PER_WORD, w_value)
         else:
             # XXX use to-be-written unwrap_char
-            index0 = index0 - self.getliteralsize() - self.headersize()
+            index0 = index0 - byteoffset
             assert index0 < len(self.bytes)
             self.setchar(index0, chr(space.unwrap_int(w_value)))
 
diff --git a/spyvm/test/test_model.py b/spyvm/test/test_model.py
--- a/spyvm/test/test_model.py
+++ b/spyvm/test/test_model.py
@@ -1,7 +1,7 @@
 import py
 from spyvm import model, shadow
 from spyvm.shadow import MethodNotFound
-from spyvm import objspace
+from spyvm import objspace, error
 
 mockclass = objspace.bootstrap_class
 
@@ -130,6 +130,14 @@
     assert space.unwrap_int(w_method.at0(space, 13)) == ord('b')
     assert space.unwrap_int(w_method.at0(space, 14)) == ord('c')
 
+def test_compiledmethod_atput0_not_aligned():
+    header = joinbits([0,2,0,0,0,0],[9,8,1,6,4,1])
+    w_method = model.W_CompiledMethod(3, header)
+    with py.test.raises(error.PrimitiveFailedError):
+        w_method.atput0(space, 7, 'lit1')
+    with py.test.raises(error.PrimitiveFailedError):
+        w_method.atput0(space, 9, space.wrap_int(5))
+
 def test_is_same_object(w_o1=model.W_PointersObject(None,0), w_o2=None):
     if w_o2 is None:
         w_o2 = w_o1


More information about the pypy-commit mailing list