timfel avatar timfel committed ea768f7

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

Comments (0)

Files changed (2)

             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)))
 

spyvm/test/test_model.py

 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
 
     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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.