forked from tinygrad/tinygrad
fix metal uaf (#964)
This commit is contained in:
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import weakref
|
||||
import numpy as np
|
||||
from tinygrad.tensor import Tensor, Device
|
||||
Device.DEFAULT = "METAL"
|
||||
|
||||
if __name__ == "__main__":
|
||||
t = Tensor.zeros(3).realize()
|
||||
wt = weakref.ref(t.lazydata.realized)
|
||||
n = t.numpy()
|
||||
t += 1
|
||||
n2 = t.numpy()
|
||||
print(wt)
|
||||
del t
|
||||
print(wt)
|
||||
print(n, n.base, n.base.base)
|
||||
print(n2, n2.base, n2.base.base)
|
||||
assert wt() is not None
|
||||
@@ -31,7 +31,7 @@ class RawBufferCopyIn(RawBuffer):
|
||||
|
||||
class RawBufferMapped(RawBufferCopyIn):
|
||||
def _buffer(self) -> memoryview: raise NotImplementedError("must be implemented")
|
||||
def toCPU(self) -> np.ndarray: return np.frombuffer(self._buffer(), dtype=self.dtype.np)
|
||||
def toCPU(self) -> np.ndarray: return np.frombuffer(self._buffer(), dtype=np.dtype(self.dtype.np, metadata={"backing": self})) # type: ignore
|
||||
def _copyin(self, x:np.ndarray) -> None: np.copyto(self.toCPU(), x.reshape(-1))
|
||||
|
||||
# this one is simple enough that i moved it out of the runtimes
|
||||
|
||||
Reference in New Issue
Block a user