diff --git a/backends/xnnpack/runtime/XNNCompiler.cpp b/backends/xnnpack/runtime/XNNCompiler.cpp index 4881844ac6d..65519ea0f1f 100644 --- a/backends/xnnpack/runtime/XNNCompiler.cpp +++ b/backends/xnnpack/runtime/XNNCompiler.cpp @@ -285,9 +285,16 @@ Error defineTensor( } ET_CHECK_OR_RETURN_ERROR( - tensor_value != nullptr, - Internal, - "Deserialized Tensor is Null, this should never happen"); + tensor_value != nullptr && tensor_value->dims() != nullptr, + InvalidProgram, + "Deserialized tensor is null, or tensor dims is null"); + + ET_CHECK_OR_RETURN_ERROR( + tensor_value->num_dims() == tensor_value->dims()->size(), + InvalidProgram, + "Tensor num_dims %u does not match dims array size %u", + tensor_value->num_dims(), + tensor_value->dims()->size()); // Get tensor dims, here we need to use a vector in order // to properly convert the uint32_t* to size_t* @@ -966,6 +973,10 @@ Error defineStaticTransposeNode( auto graph_node = node->xnode_union_as_XNNStaticTranspose(); // Get tensor dims, we need to convert the uint32_t* to size_t* + ET_CHECK_OR_RETURN_ERROR( + graph_node->perm() != nullptr, + InvalidProgram, + "StaticTranspose: perm is null"); std::vector dims_data = flatbufferDimsToVector(graph_node->perm()); xnn_status status = xnn_define_static_transpose( subgraph_ptr, @@ -1031,6 +1042,11 @@ Error defineStaticConstantPadNode( const fb_xnnpack::XNNStaticConstantPad* graph_node = node->xnode_union_as_XNNStaticConstantPad(); + ET_CHECK_OR_RETURN_ERROR( + graph_node->pre_paddings() != nullptr && + graph_node->post_paddings() != nullptr, + InvalidProgram, + "StaticConstantPad: pre_paddings or post_paddings is null"); std::vector pre_paddings_dims = flatbufferDimsToVector(graph_node->pre_paddings()); std::vector post_paddings_dims = @@ -1111,6 +1127,10 @@ Error defineStaticReshapeNode( auto graph_node = node->xnode_union_as_XNNStaticReshape(); // Get tensor dims, we need to convert the uint32_t* to size_t* + ET_CHECK_OR_RETURN_ERROR( + graph_node->new_shape() != nullptr, + InvalidProgram, + "StaticReshape: new_shape is null"); std::vector dims_data = flatbufferDimsToVector(graph_node->new_shape()); xnn_status status = xnn_define_static_reshape( @@ -1406,6 +1426,10 @@ Error defineStaticSliceNode( auto graph_node = node->xnode_union_as_XNNStaticSlice(); + ET_CHECK_OR_RETURN_ERROR( + graph_node->offsets() != nullptr && graph_node->sizes() != nullptr, + InvalidProgram, + "StaticSlice: offsets or sizes is null"); std::vector offsets = flatbufferDimsToVector(graph_node->offsets()); std::vector sizes = flatbufferDimsToVector(graph_node->sizes());