message: Check against the size of a std::vector to prevent out-of-boundary access.
diff: @@ -351,6 +351,9 @@ absl::optional<uint64_t> VerifyAndCountSparseElements(const Tensor& tensor) {
  for (int i = 0; i < block_rank; i++) {
  int original_block_dim =
  sparsity->traversal_order()->Get(i + original_rank);
  + if (original_block_dim < 0 || original_block_dim >= total_dims) {
  + return absl::nullopt;
  + }
  int block_dim_size =
  sparsity->dim_metadata()->Get(i + original_rank)->dense_size();
  if (block_dim_size == 0) {
  @@ -358,7 +361,12 @@ absl::optional<uint64_t> VerifyAndCountSparseElements(const Tensor& tensor) {
  }
  expanded_dim_sizes[original_block_dim] = block_dim_size;
  - expanded_dim_sizes[sparsity->block_map()->Get(i)] /= block_dim_size;
  +
  + int mapped_block_dim = sparsity->block_map()->Get(i);
  + if (mapped_block_dim < 0 || mapped_block_dim >= total_dims) {
  + return absl::nullopt;
  + }
  + expanded_dim_sizes[mapped_block_dim] /= block_dim_size;
  }
  return VerifyAndCountElements(*sparsity, expanded_dim_sizes);
  