Commit 07ffdaf
committed
gh-152166: Fix array.array.fromlist() exposing uninitialized memory on reentrant resize
array.array.fromlist() preallocated n slots with array_resize() and then
filled them at an index recomputed from the live Py_SIZE(self) each
iteration, guarding only against the source list changing size. When an
element's __index__ resized self as a side effect of the setitem call, the
write index slid forward, the reserved slots were left unwritten, and the
array exposed uninitialized heap memory (with the items misplaced) on a
successful return.
Fill the fixed slot old_size + i instead, and raise RuntimeError if self is
resized mid-iteration, mirroring the existing list-mutation guard.
This is distinct from gh-144128/gh-144138, which fixed a use-after-free in
the *_setitem conversion helpers and did not touch fromlist's index logic.1 parent 30aeeb3 commit 07ffdaf
3 files changed
Lines changed: 38 additions & 2 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Library
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
85 | 107 | | |
86 | 108 | | |
87 | 109 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1805 | 1805 | | |
1806 | 1806 | | |
1807 | 1807 | | |
1808 | | - | |
1809 | | - | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
1810 | 1814 | | |
1811 | 1815 | | |
1812 | 1816 | | |
| |||
1816 | 1820 | | |
1817 | 1821 | | |
1818 | 1822 | | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
1819 | 1829 | | |
1820 | 1830 | | |
1821 | 1831 | | |
| |||
0 commit comments