You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
I reported this in #8133, but I think it got lost in my confusion about scalar values in mxnet. But I think this deserves a separate issue.
Unlike numpy, mxnet doesn't support rank 0 arrays, but uses an empty tuple to represent unknown shapes. mx.nd still allows the creation of rank 0 arrays however. This leads to confusion during shape inference and allows out of bounds memory reads and writes:
a=mx.sym.var('a')
b=mx.sym.var('b')
c=a+ba_=mx.nd.ones(()) # Has size 1, but bind assumes it has shape (5,)b_=mx.nd.ones(5)
func=c.bind(mx.cpu(), {'a': a_, 'b': b_})
func.forward()
func.outputs[0].asnumpy()
array([ 2.00000000e+00, 2.52435490e-29, 8.84247875e+05,
1.08446609e-19, -1.92860745e-26], dtype=float32)
We can write to invalid memory (and crash the process or potentially get arbitrary code execution) by providing a gradient buffer with the wrong shape