@@ -1749,16 +1749,16 @@ static Status CopySparseData(size_t n_sparse_elements,
17491749 std::function<void (size_t from_idx, size_t to_idx)> copier) {
17501750 Status status = Status::OK ();
17511751 TensorShape indices_shape (indices.dims ().data (), indices.dims ().size ());
1752- const auto nnz_elements = narrow< size_t >( indices_shape.Size () );
1752+ const int64_t nnz_elements = indices_shape.Size ();
17531753
1754- std::vector <int64_t > indices_values; // used for conversion of smaller size indices
1754+ InlinedVector <int64_t > indices_values; // used for conversion of smaller size indices
17551755 std::vector<uint8_t > unpack_buffer;
17561756 gsl::span<const int64_t > indices_data;
17571757 const bool has_raw_data = utils::HasRawData (indices);
17581758 switch (indices.data_type ()) {
17591759 case ONNX_NAMESPACE::TensorProto_DataType_INT64:
17601760 if (has_raw_data) {
1761- ORT_RETURN_IF_NOT (indices.raw_data ().size () == (nnz_elements * sizeof (int64_t )),
1761+ ORT_RETURN_IF_NOT (indices.raw_data ().size () == (SafeInt< size_t >( nnz_elements) * sizeof (int64_t )),
17621762 " Sparse Indices raw data size does not match expected." );
17631763 ORT_RETURN_IF_ERROR (UnpackInitializerData (indices, model_path, unpack_buffer));
17641764 indices_data = ReinterpretAsSpan<const int64_t >(gsl::make_span (unpack_buffer));
@@ -1770,7 +1770,7 @@ static Status CopySparseData(size_t n_sparse_elements,
17701770 break ;
17711771 case ONNX_NAMESPACE::TensorProto_DataType_INT32: {
17721772 if (has_raw_data) {
1773- ORT_RETURN_IF_NOT (indices.raw_data ().size () == (nnz_elements * sizeof (int32_t )),
1773+ ORT_RETURN_IF_NOT (indices.raw_data ().size () == (SafeInt< size_t >( nnz_elements) * sizeof (int32_t )),
17741774 " Sparse Indices raw data size does not match expected." );
17751775 ORT_RETURN_IF_ERROR (UnpackInitializerData (indices, model_path, unpack_buffer));
17761776 auto int32_span = ReinterpretAsSpan<const int32_t >(gsl::make_span (unpack_buffer));
@@ -1787,7 +1787,7 @@ static Status CopySparseData(size_t n_sparse_elements,
17871787 }
17881788 case ONNX_NAMESPACE::TensorProto_DataType_INT16: {
17891789 if (has_raw_data) {
1790- ORT_RETURN_IF_NOT (indices.raw_data ().size () == (nnz_elements * sizeof (int16_t )),
1790+ ORT_RETURN_IF_NOT (indices.raw_data ().size () == (SafeInt< size_t >( nnz_elements) * sizeof (int16_t )),
17911791 " Sparse Indices raw data size does not match expected." );
17921792 ORT_RETURN_IF_ERROR (UnpackInitializerData (indices, model_path, unpack_buffer));
17931793 auto int16_span = ReinterpretAsSpan<const int16_t >(gsl::make_span (unpack_buffer));
@@ -1804,7 +1804,7 @@ static Status CopySparseData(size_t n_sparse_elements,
18041804 }
18051805 case ONNX_NAMESPACE::TensorProto_DataType_INT8: {
18061806 if (has_raw_data) {
1807- ORT_RETURN_IF_NOT (indices.raw_data ().size () == nnz_elements,
1807+ ORT_RETURN_IF_NOT (indices.raw_data ().size () == SafeInt< size_t >( nnz_elements) ,
18081808 " Sparse Indices raw data size does not match expected." );
18091809 ORT_RETURN_IF_ERROR (UnpackInitializerData (indices, model_path, unpack_buffer));
18101810 auto int8_span = ReinterpretAsSpan<const int8_t >(gsl::make_span (unpack_buffer));
0 commit comments