Skip to content

Missing strides validation for usm_ndarray constructor #2881

Description

@antonwolfy

There is a missing validation for the input keyword strides passed to usm_ndarray constructor which can cause walking outside of the memory:

import dpctl, dpctl.tensor as dpt

dpctl.__version__
# Out: '0.22.0dev0+114.g0797836be2'

# create a buffer with ones
buf = dpt.ones(24, dtype=np.float64)

# new array points outside the buffer memory:
a = dpt.usm_ndarray((2, 3, 4), strides=(1, 16, 128), dtype=buf.dtype)
a
# Out:
# usm_ndarray([[[0., 0., 0., 0.],
#               [0., 0., 0., 0.],
#               [0., 0., 0., 0.]],
# 
#              [[0., 0., 0., 0.],
#               [0., 0., 0., 0.],
#               [0., 0., 0., 0.]]])

# new array points outside the buffer memory:
a = dpt.usm_ndarray((2, 3, 4), strides=(-1, 1, 1), dtype=buf.dtype)
a
# Out:
# usm_ndarray([[[0., 0., 0., 0.],
#               [0., 0., 0., 0.],
#               [0., 0., 0., 0.]],
# 
#              [[0., 0., 0., 0.],
#               [0., 0., 0., 0.],
#               [0., 0., 0., 0.]]])

Metadata

Metadata

Labels

No labels
No labels

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions