diff --git a/onnxruntime/core/providers/cpu/nn/Unpool.cc b/onnxruntime/core/providers/cpu/nn/Unpool.cc index 391326dbb2..e108f67712 100644 --- a/onnxruntime/core/providers/cpu/nn/Unpool.cc +++ b/onnxruntime/core/providers/cpu/nn/Unpool.cc @@ -26,6 +26,7 @@ ONNX_CPU_OPERATOR_KERNEL( Status MaxUnpool::Compute(OpKernelContext* context) const { // Get pooled values tensor const Tensor* X = context->Input(0); + if (X == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch"); const TensorShape& X_shape = X->Shape(); const float* X_data = X->template Data(); @@ -62,12 +63,13 @@ Status MaxUnpool::Compute(OpKernelContext* context) const { bool padsInferred = false; if (num_inputs_ == 3) { - auto& tensor_shape = *context->Input(2); - ORT_RETURN_IF_NOT(tensor_shape.Shape().GetDims().size() == 1, "Shape must be 1 dimensional as it's tensor data is a shape"); + auto tensor_shape = context->Input(2); + if (tensor_shape == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch"); + ORT_RETURN_IF_NOT(tensor_shape->Shape().GetDims().size() == 1, "Shape must be 1 dimensional as it's tensor data is a shape"); // Turn the shape tensor data into an actual shape - const int64_t* p_shape = tensor_shape.template Data(); - std::vector shape{p_shape, p_shape + tensor_shape.Shape().Size()}; + const int64_t* p_shape = tensor_shape->template Data(); + std::vector shape{p_shape, p_shape + tensor_shape->Shape().Size()}; givenOutputShape = shape; inferredPads.resize(inferredOutputShape.size() * 2, 0); diff --git a/onnxruntime/core/providers/cuda/tensor/identity_op.h b/onnxruntime/core/providers/cuda/tensor/identity_op.h index f66a11faf7..d83fd541b3 100644 --- a/onnxruntime/core/providers/cuda/tensor/identity_op.h +++ b/onnxruntime/core/providers/cuda/tensor/identity_op.h @@ -17,6 +17,7 @@ class IdentityOp final : public CudaKernel { Status ComputeInternal(OpKernelContext* context) const override { const Tensor* X = context->Input(0); + if (X == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch"); const TensorShape& shape = X->Shape(); Tensor* Y = context->Output(0, shape); auto X_type = X->DataType(); diff --git a/onnxruntime/core/providers/cuda/tensor/transpose.cc b/onnxruntime/core/providers/cuda/tensor/transpose.cc index 670e4f2843..d443336deb 100644 --- a/onnxruntime/core/providers/cuda/tensor/transpose.cc +++ b/onnxruntime/core/providers/cuda/tensor/transpose.cc @@ -21,7 +21,9 @@ namespace cuda { template Status Transpose::ComputeInternal(OpKernelContext* ctx) const { - const Tensor& X = *ctx->Input(0); + const Tensor* X_ptr = ctx->Input(0); + if (X_ptr == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch"); + const Tensor& X = *X_ptr; const TensorShape& input_shape = X.Shape(); const std::vector& input_dims = input_shape.GetDims(); size_t rank = input_dims.size(); diff --git a/onnxruntime/core/providers/mkldnn/math/sum.cc b/onnxruntime/core/providers/mkldnn/math/sum.cc index d08bc62ea7..5b7794ab62 100644 --- a/onnxruntime/core/providers/mkldnn/math/sum.cc +++ b/onnxruntime/core/providers/mkldnn/math/sum.cc @@ -192,6 +192,7 @@ Status Sum::Compute(OpKernelContext* context) const { std::vector src_dims; const Tensor* X1 = context->Input(0); + if (X1 == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch"); Tensor* Y = context->Output(0, X1->Shape()); int dimensions = static_cast(X1->Shape().NumDimensions()); @@ -204,6 +205,7 @@ Status Sum::Compute(OpKernelContext* context) const { for (int i = 0; i < num_inputs; i++) { const Tensor* X = context->Input(i); + if (X == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch"); mkldnn::memory::dims src_dims_mkl( X->Shape().GetDims().begin(), X->Shape().GetDims().end()); src_dims.push_back(src_dims_mkl);