GH-50054: [C++][IPC] Validate indices buffer size in ReadSparseCOOIndex#50055
Open
metsw24-max wants to merge 1 commit into
Open
GH-50054: [C++][IPC] Validate indices buffer size in ReadSparseCOOIndex#50055metsw24-max wants to merge 1 commit into
metsw24-max wants to merge 1 commit into
Conversation
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
ReadSparseCOOIndexbuilds the indicesTensorof shape{non_zero_length, ndim}overindicesBufferwith no size check, unlike the siblingReadSparseCSXIndex. A crafted COO message with a largenon_zero_lengthand 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). Anon_zero_lengthnearINT64_MAXalso overflows thenon_zero_length * ndim * byte_widthsize product.What changes are included in this PR?
A minimum-size guard on
indicesBufferinReadSparseCOOIndex, mirroring the existing check inReadSparseCSXIndexand usingMultiplyWithOverflowfor 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::Invalidinstead 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.