Commit 7b1b994
committed
gh-154566: Fix array.byteswap() corrupting 'Zd' arrays with more than one element
The 16-byte-item loop in array_array_byteswap_impl() advanced the
buffer pointer by only 8 bytes per iteration, even though each
iteration swaps a full 16-byte item (two independent 8-byte halves
for the real/imaginary double components). This caused every item
after the first to overlap the previous iteration's byte window and
come out scrambled.
A single byteswap() call gave wrong bytes for the second item onward.
Calling byteswap() twice happened to round-trip back to the original
value (the corruption is self-canceling under double application),
which is why the existing test suite -- which only checked a
double-call round-trip -- didn't catch it. Added a regression test
that checks the actual byte-level result of a single call.1 parent 66e313f commit 7b1b994
3 files changed
Lines changed: 21 additions & 1 deletion
File tree
- Lib/test
- Misc/NEWS.d/next/Library
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1611 | 1611 | | |
1612 | 1612 | | |
1613 | 1613 | | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
1614 | 1628 | | |
1615 | 1629 | | |
1616 | 1630 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1617 | 1617 | | |
1618 | 1618 | | |
1619 | 1619 | | |
1620 | | - | |
| 1620 | + | |
1621 | 1621 | | |
1622 | 1622 | | |
1623 | 1623 | | |
| |||
0 commit comments