Skip to content

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

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});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions