Skip to content

Prevent buffer overflow when assigning to fixed-dimension xtensor with mismatched rank#2907

Merged
JohanMabille merged 3 commits into
xtensor-stack:masterfrom
Alex-PLACET:fixed-dimension-resize-dimension-mismatch
May 11, 2026
Merged

Prevent buffer overflow when assigning to fixed-dimension xtensor with mismatched rank#2907
JohanMabille merged 3 commits into
xtensor-stack:masterfrom
Alex-PLACET:fixed-dimension-resize-dimension-mismatch

Conversation

@Alex-PLACET
Copy link
Copy Markdown
Contributor

@Alex-PLACET Alex-PLACET commented May 5, 2026

Checklist

  • The title and commit message(s) are descriptive.
  • Small commits made to fix your PR have been squashed to avoid history pollution.
  • Tests have been added for new features or bug fixes.
  • API of new functions and classes are documented.

Description

Addressing #2792

Assigning a higher-dimensional expression to a fixed-rank [xtensor<T, N>] caused a buffer overflow (stack smashing) in release builds:

auto a = xt::xtensor<float, 1>::from_shape({2});
a = xt::expand_dims(a, 0);  // expand_dims returns 2D view, shape {1, 2}
// buffer overflow: resize truncates shape {1,2} -> {1}, then copies 2 elements into 1 element buffer

@Alex-PLACET Alex-PLACET linked an issue May 5, 2026 that may be closed by this pull request
@Alex-PLACET Alex-PLACET marked this pull request as ready for review May 5, 2026 11:43
@JohanMabille JohanMabille merged commit 8adbd1c into xtensor-stack:master May 11, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

*** stack smashing detected ***: terminated

2 participants