You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "metsw24-max (via GitHub)" <gi...@apache.org> on 2026/05/27 12:54:33 UTC
[PR] GH-50054: [C++][IPC] Validate indices buffer size in ReadSparseCOOIndex [arrow]
metsw24-max opened a new pull request, #50055:
URL: https://github.com/apache/arrow/pull/50055
### Rationale for this change
`ReadSparseCOOIndex` builds the indices `Tensor` of shape `{non_zero_length, ndim}` over `indicesBuffer` with no size check, unlike the sibling `ReadSparseCSXIndex`. A crafted COO message with a large `non_zero_length` and a small buffer produces an index tensor that overruns its buffer, giving an out-of-bounds read when the sparse tensor is consumed (for example, converted to dense). A `non_zero_length` near `INT64_MAX` also overflows the `non_zero_length * ndim * byte_width` size product.
### What changes are included in this PR?
A minimum-size guard on `indicesBuffer` in `ReadSparseCOOIndex`, mirroring the existing check in `ReadSparseCSXIndex` and using `MultiplyWithOverflow` for the size computation.
### Are these changes tested?
The guard is a no-op for the valid inputs covered by the round-trip tests in `cpp/src/arrow/ipc/tensor_test.cc`; the rejection and overflow behaviour was checked against a standalone reproducer of the size computation.
### Are there any user-facing changes?
Reading a malformed sparse COO tensor message now returns `Status::Invalid` instead of constructing an out-of-bounds index tensor.
**This PR contains a "Critical Fix".** A malformed IPC SparseTensor (COO) message could trigger an out-of-bounds read when the resulting sparse tensor is consumed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50054: [C++][IPC] Validate indices buffer size in ReadSparseCOOIndex [arrow]
Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #50055:
URL: https://github.com/apache/arrow/pull/50055#discussion_r3498660244
##########
cpp/src/arrow/ipc/reader.cc:
##########
@@ -2293,6 +2293,14 @@ Result<std::shared_ptr<SparseIndex>> ReadSparseCOOIndex(
file->ReadAt(indices_buffer->offset(), indices_buffer->length(),
/*allow_short_read=*/false));
std::vector<int64_t> indices_shape({non_zero_length, ndim});
+ int64_t indices_minimum_bytes;
+ if (MultiplyWithOverflow(non_zero_length, ndim,
+ &indices_minimum_bytes) ||
+ MultiplyWithOverflow(indices_minimum_bytes, indices_elsize,
+ &indices_minimum_bytes) ||
Review Comment:
```suggestion
if (MultiplyWithOverflow(non_zero_length, ndim, &indices_minimum_bytes) ||
MultiplyWithOverflow(indices_minimum_bytes, indices_elsize,
&indices_minimum_bytes) ||
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50054: [C++][IPC] Validate indices buffer size in ReadSparseCOOIndex [arrow]
Posted by "metsw24-max (via GitHub)" <gi...@apache.org>.
metsw24-max commented on PR #50055:
URL: https://github.com/apache/arrow/pull/50055#issuecomment-4781117904
gentle ping
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50054: [C++][IPC] Validate indices buffer size in ReadSparseCOOIndex [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #50055:
URL: https://github.com/apache/arrow/pull/50055#issuecomment-4798625998
@rok Can you take a look at this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50054: [C++][IPC] Validate indices buffer size in ReadSparseCOOIndex [arrow]
Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #50055:
URL: https://github.com/apache/arrow/pull/50055#discussion_r3498122014
##########
cpp/src/arrow/ipc/reader.cc:
##########
@@ -2293,6 +2293,14 @@ Result<std::shared_ptr<SparseIndex>> ReadSparseCOOIndex(
file->ReadAt(indices_buffer->offset(), indices_buffer->length(),
/*allow_short_read=*/false));
std::vector<int64_t> indices_shape({non_zero_length, ndim});
+ int64_t indices_minimum_bytes;
+ if (arrow::internal::MultiplyWithOverflow(non_zero_length, ndim,
+ &indices_minimum_bytes) ||
+ arrow::internal::MultiplyWithOverflow(indices_minimum_bytes, indices_elsize,
Review Comment:
```suggestion
if (MultiplyWithOverflow(non_zero_length, ndim,
&indices_minimum_bytes) ||
MultiplyWithOverflow(indices_minimum_bytes, indices_elsize,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50054: [C++][IPC] Validate indices buffer size in ReadSparseCOOIndex [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #50055:
URL: https://github.com/apache/arrow/pull/50055#issuecomment-4850161110
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit a6c201816e1a6dcd6dfa5d335a03afe5fb17423f.
There were no benchmark performance regressions. 🎉
The [full Conbench report](https://github.com/apache/arrow/runs/84452836918) has more details. It also includes information about 21 possible false positives for unstable benchmarks that are known to sometimes produce them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50054: [C++][IPC] Validate indices buffer size in ReadSparseCOOIndex [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #50055:
URL: https://github.com/apache/arrow/pull/50055#issuecomment-4554674626
:warning: GitHub issue #50054 **has been automatically assigned in GitHub** to PR creator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50054: [C++][IPC] Validate indices buffer size in ReadSparseCOOIndex [arrow]
Posted by "rok (via GitHub)" <gi...@apache.org>.
rok merged PR #50055:
URL: https://github.com/apache/arrow/pull/50055
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org