Commit 5cb33878 authored by Adam Procter's avatar Adam Procter Committed by GitHub

Fix use-after-free in `TensorViewLayout::get_shape()` (#174)

* isolate graph building / execution scope in some unit tests (this triggered the user-after-free which was also observed from TF)

* Change descriptor::layout::TensorViewLayout to store a shared pointer to the TensorViewType rather than a reference to the TensorView
parent c3dfdf5a
......@@ -35,7 +35,7 @@ namespace ngraph
{
protected:
TensorViewLayout(const ngraph::descriptor::TensorView& tensor_view)
: m_tensor_view(tensor_view)
: m_tensor_view_type(tensor_view.get_tensor_view_type())
{
}
......@@ -53,19 +53,14 @@ namespace ngraph
const element::Type& get_element_type() const
{
return m_tensor_view.get_tensor_view_type()->get_element_type();
return m_tensor_view_type->get_element_type();
}
const Shape& get_shape() const
{
return m_tensor_view.get_tensor_view_type()->get_shape();
}
const Shape& get_shape() const { return m_tensor_view_type->get_shape(); }
/// Where this view is located in the buffer.
const BufferPos& get_buffer_pos() const { return m_buffer_pos; }
BufferPos& get_buffer_pos() { return m_buffer_pos; }
protected:
const ngraph::descriptor::TensorView& m_tensor_view;
std::shared_ptr<const TensorViewType> m_tensor_view_type;
BufferPos m_buffer_pos;
};
}
......
......@@ -341,14 +341,19 @@ TEST(execute, test_concat_vector)
TEST(execute, test_divide)
{
auto shape = Shape{2, 2};
auto A = make_shared<op::Parameter>(element::Float32::element_type(), shape);
auto B = make_shared<op::Parameter>(element::Float32::element_type(), shape);
auto rt = make_shared<TensorViewType>(element::Float32::element_type(), shape);
auto f = make_shared<Function>(make_shared<op::Divide>(A, B), rt, op::Parameters{A, B});
auto make_external = []() {
auto shape = Shape{2, 2};
auto A = make_shared<op::Parameter>(element::Float32::element_type(), shape);
auto B = make_shared<op::Parameter>(element::Float32::element_type(), shape);
auto rt = make_shared<TensorViewType>(element::Float32::element_type(), shape);
auto f = make_shared<Function>(make_shared<op::Divide>(A, B), rt, op::Parameters{A, B});
auto external = make_shared<ngraph::runtime::ExternalFunction>(f);
auto cf = external->make_call_frame();
auto external = make_shared<ngraph::runtime::ExternalFunction>(f);
return external;
};
auto shape = Shape{2, 2};
auto cf = make_external()->make_call_frame();
// Create some tensors for input/output
auto a = ngraph::runtime::make_tensor<element::Float32>(shape);
......@@ -408,16 +413,23 @@ TEST(execute, test_dot_0_0)
TEST(execute, test_dot_matrix_2x0_0x2)
{
auto make_external = []() {
auto shape_a = Shape{2, 0};
auto A = make_shared<op::Parameter>(element::Float32::element_type(), shape_a);
auto shape_b = Shape{0, 2};
auto B = make_shared<op::Parameter>(element::Float32::element_type(), shape_b);
auto shape_r = Shape{2, 2};
auto rt = make_shared<TensorViewType>(element::Float32::element_type(), shape_r);
auto f = make_shared<Function>(make_shared<op::Dot>(A, B), rt, op::Parameters{A, B});
auto external = make_shared<ngraph::runtime::ExternalFunction>(f);
return external;
};
auto shape_a = Shape{2, 0};
auto A = make_shared<op::Parameter>(element::Float32::element_type(), shape_a);
auto shape_b = Shape{0, 2};
auto B = make_shared<op::Parameter>(element::Float32::element_type(), shape_b);
auto shape_r = Shape{2, 2};
auto rt = make_shared<TensorViewType>(element::Float32::element_type(), shape_r);
auto f = make_shared<Function>(make_shared<op::Dot>(A, B), rt, op::Parameters{A, B});
auto external = make_shared<ngraph::runtime::ExternalFunction>(f);
auto cf = external->make_call_frame();
auto cf = make_external()->make_call_frame();
// Create some tensors for input/output
auto a = ngraph::runtime::make_tensor<element::Float32>(shape_a);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment