Commit 8adbd1c
authored
Prevent buffer overflow when assigning to fixed-dimension xtensor with mismatched rank (#2907)
# Checklist
- [x] The title and commit message(s) are descriptive.
- [x] Small commits made to fix your PR have been squashed to avoid
history pollution.
- [x] Tests have been added for new features or bug fixes.
- [x] 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:
```c++
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
```
---------
Co-authored-by: Alexis Placet <2400067+Alex-PLACET@users.noreply.github.com>1 parent 2b01100 commit 8adbd1c
2 files changed
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
997 | 997 | | |
998 | 998 | | |
999 | 999 | | |
1000 | | - | |
| 1000 | + | |
1001 | 1001 | | |
1002 | 1002 | | |
1003 | | - | |
| 1003 | + | |
1004 | 1004 | | |
1005 | 1005 | | |
1006 | 1006 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
170 | 177 | | |
0 commit comments