Oneflow-Inc / oneflow

OneFlow is a deep learning framework designed to be user-friendly, scalable and efficient.
http://www.oneflow.org
Apache License 2.0
5.79k stars 658 forks source link

Missing range check for negative index parameter in oneflow.scatter. #10463

Open Redmept1on opened 3 months ago

Redmept1on commented 3 months ago

Summary

Missing range check for negative index parameter in oneflow.scatter. When index as a positive number exceeds the range of size, core dumped occurs, and when index as a negative number exceeds the range of size, no error is reported.

Code to reproduce bug

import oneflow as flow
import numpy as np

input = flow.ones((3,5))*2
index = flow.tensor(np.array([[0,-10000,2],[0,1,4]], ), dtype=flow.int32)
src = flow.Tensor(np.array([[0,10,20,30,40],[50,60,70,80,90]]))
out = flow.scatter(input, 1, index, src)
print(out)

image

import oneflow as flow
import numpy as np

input = flow.ones((3,5))*2
index = flow.tensor(np.array([[0,10000,2],[0,1,4]], ), dtype=flow.int32)
src = flow.Tensor(np.array([[0,10,20,30,40],[50,60,70,80,90]]))
out = flow.scatter(input, 1, index, src)
print(out)

image the core dumped will last more than 10 secs.

System Information

Redmept1on commented 3 months ago

in 'oneflow.scatter_add', it also miss the range check negative situation image positve situation(last about 10 secs) image