Skip to content

[C++] Tensor::Make skips buffer-size check for row-major (implicit strides) tensors #50063

@metsw24-max

Description

@metsw24-max

When Tensor::Make is called without explicit strides, ValidateTensorParameters (cpp/src/arrow/tensor.cc) only computes row-major strides and never verifies the data buffer is large enough for the shape. The buffer-overrun guard in CheckTensorStridesValidity runs only when strides are supplied. A row-major tensor whose shape exceeds its backing buffer is accepted, leading to out-of-bounds reads when the tensor is consumed.

This is reachable from IPC ReadTensor: the shape comes from the Tensor flatbuffer and the data is the message body, whose size is independent of the shape, and the flatbuffer commonly omits strides (row-major).

auto data = Buffer::Wrap(std::vector<double>{1, 2});  // 16 bytes
// shape needs 3*100*8 = 2400 bytes; currently returns OK
auto t = Tensor::Make(float64(), data, {3, 100});

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions